MVVM with Co-ordinator

MVVM (Model-View-ViewModel) Purpose: Separate business logic, UI and data to improve testability and structure. 1. Model 2. View 3. ViewModel Coordinator Pattern Purpose: Decouples navigation logic from view controllers. This helps to: Coordinator Responsibilities:

SOLID Principle

The SOLID principles are five design principles that help create maintainable, scalable, and testable software. 1. Single Responsibility Principle (SRP) A class should have only one reason to change (i.e only one responsibility). Example (Violating SRP) Example (Following SRP) 2.Open/Closed Principle A class should be open for extension but closed …

Design Patterns in iOS

Design patterns help in structuring code efficiently and making it reusable, maintainable, and scalable. Here are some commonly used design patterns in Swift with examples: 1. Creational Design Patterns (Object Creation) 1.1 Singleton Pattern Ensures only one instance of a class exists. 1.2 Factory Pattern Creates objects without specifying the …

Dependency Injection in iOS

Dependency Injection (DI) in Swift is a design pattern that allows to inject dependencies into a class instead of letting the class create them itself. This improves testability, modularity and flexibility. There are three main types of Dependency Injection in Swift: 1. Constructor Injection (Initialiser Injection) 2. Property Injection 3. …

Architecture Patterns in iOS

1. MVC (Model-View-Controller) MVC is the default architecture pattern where 2. MVVM (Model-View-ViewModel) MVVM with Dependency Inversion (DI) Difference Between MVVM and MVC MVVM (Model-View-ViewModel) and MVC (Model-View-Controller) are two popular architectural patterns used in iOS app development, particularly when working with Swift. Each pattern has its own set of …

View Controller Life Cycle

View Controller Life Cycle Methods init(coder)/init(nibName:bundle:): Called when the view controller is created programmatically or via Storyboard. loadView() Creates the view for the view controller (usually overridden if creating views manually). viewDidLoad() Called once when the view is loaded into memory. viewWillAppear() Called before the view appears on the screen …

Application Life Cycle

The app transitions through the following states in its life cycle: The application life cycle is managed by the AppDelegate and SceneDelegate. 1.application(_:didFinishLaunchingWithOptions:) 2.applicationDidBecomeActive(_:) 3.applicationWillResignActive(_:) 4.applicationDidEnterBackground(_:) Called when the app enters the background. 5.applicationWillEnterForeground(_:) Called as the app transitions from background to foreground. 6.applicationWillTerminate(_:) Called when the app is about …

Lazy Properties

A lazy property is a property whose initial value is not calculated until the first time it is accessed.

TypeAlias

A typealias is used to provide an alternative name for an existing type. It helps improve code readability, especially when working with complex or verbose types. It does not create a new type; it only creates a new name for an existing type.

Defer

defer is a statement used to execute a block of code just before the current scope e.g a function or loop exits.