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 …
OperationQueue
It’s built on top of Grand Central Dispatch (GCD) and provides a higher-level abstraction for managing concurrent operations. It’s an abstract class and never used directly. We can make use of the system-defined BlockOperation subclass or by creating your own subclass and start an operation by adding it to an OperationQueue or …
Global Dispatch Queues
GCD provides a set of global dispatch queues that are managed by the system. These queues are categorised into different quality-of-service (QoS) classes, indicating their priority. Main Dispatch Queue: The Main Dispatch Queue is a special serial dispatch queue associated with the main thread of your application. It’s the primary …
Grand Central Dispatch (GCD)
Grand Central Dispatch is a low-level API provided by Apple for managing concurrent operations. GCD abstracts away many of the complexities of thread management and provides a simple and efficient way to execute tasks concurrently. It provides a set of APIs for managing tasks and executing them concurrently on multicore …