Protocols

Protocols in Swift define a blueprint of methods, properties, and other requirements that a conforming type must implement. They are a cornerstone of protocol-oriented programming, which Swift emphasizes over traditional inheritance. Syntax Conforming to a Protocol A class, struct, or enum can conform to a protocol by implementing all its …

Object Oriented Programming(OOP)

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects which can contain data (properties) and code (methods). Swift, as a modern programming language, fully supports OOP principles, including encapsulation, inheritance, polymorphism and abstraction. Core Principles of OOP Encapsulation Inheritance 1.Single Inheritance In Swift, a subclass can …

Access Control

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 …