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 …
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 …