Class

Classes are reference types used to define reusable and flexible blueprints for objects. Classes can have properties, methods, initialisers, deinitialisers and can conform to protocols. They also support inheritance, which makes them powerful for building complex systems. Characteristic of Class Initialiser(Constructor) Classes can have multiple initialisers, and these can be …

Struct

Struct are similar to classes but have distinct features and are often preferred in value-oriented programming. Features Mutating Methods To modify a structure’s properties within a method, you need to mark the method as mutating Use Cases of Structs

Closures

Closures are self-contained blocks of functionality that can be passed around and used in your code. They can capture and store references to variables and constants from their surrounding context, making them extremely powerful for functional programming. 1.Closure as a Function Argument 2.Trailing Closure If a closure is the last …

Optionals in Swift

Optionals in Swift are a powerful feature that allows a variable to hold either a value or nil (no value). This helps handle the absence of a value safely and avoids runtime crashes caused by null pointers. Unwrapping Optionals 1.Force Unwrapping Access the value of an optional using ! if …

Enums

Enums define a group of related values in a type-safe way. They are particularly useful for defining states, options, or categories that a variable can have. Raw Values Enums can have raw values associated with each case. The raw value must be of the same type and unique. Associated Values …