1.Open Access Used primarily in frameworks to allow subclassing and overriding outside the module 2.Public Access Allows usage outside the module but does not allow subclassing or overriding outside the module. 3.Internal Access Accessible anywhere within the same module. 4.Fileprivate Access Limits access to the enclosing declaration or extensions within …
Automatic Reference Counting
Swift uses Automatic Reference Counting (ARC) to manage the memory of instances of classes. ARC automatically keeps track of references to class instances and deallocates them when they are no longer needed, freeing up memory. Retail Cycle and Memory Leak A retain cycle occurs when two or more class instances …
Initializer
An initializer is a special method that prepares an instance of a class, structure, or enumeration for use. Initializers set up the initial state of an object by assigning values to its properties and performing any required setup. Types of Initializers 1. Designated Initializer 2. Convenience Initializer 3. Failable Initializer …
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 …
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 …
Sets
A Set in Swift is an unordered collection of unique elements. Unlike an Array, it does not allow duplicate values and does not maintain the order of elements. Key Set Operations Set Operations 1. Union Combines all unique elements from two sets. 2.Intersection Finds common elements between two sets. Difference …
Dictionary
A dictionary in Swift is a collection type that stores key-value pairs. Each key is unique and you use it to access its corresponding value. Iterating Over a Dictionary