Swift
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Optionals
-
Section 4: Object-Oriented and Value Types
-
Section 5: Memory Management
-
Section 6: Generics and Error Handling
-
Section 7: Concurrency
-
Section 8: Working with Collections
-
Section 9: Codable and Data Handling
-
Section 10: Protocol-Oriented Programming
-
Section 11: Testing and Tooling
-
Section 12: Practical Projects
-
Section 13: Interview Practice
-
Section 14: More Practice Exercises
-
Section 15: More Standard Library
-
Section 16: Advanced Concurrency
-
Section 17: Foundation Framework Deep Dive
-
Section 18: URLSession and Networking Deep Dive
-
Section 19: Combine Framework
-
Section 20: SwiftUI Fundamentals for Swift Developers
-
Section 21: Server-Side Swift with Vapor
-
Section 22: Swift Package Manager Deep Dive
-
Section 23: Swift Concurrency Deep Dive
-
Section 24: More Language Features
-
Section 25: Error Handling Deep Dive
-
Section 26: Testing Deep Dive
-
Section 27: Data Structures and Algorithms in Swift
-
Section 28: More Practice Exercises
-
Section 29: More Interview Practice
-
Section 30: Swift Macros (Swift 5.9+)
-
Section 31: Property Wrappers Ecosystem
-
Section 32: Swift Interop Deep Dive
-
Section 33: iOS App Architecture Patterns
-
Section 34: Performance and Debugging
-
Section 35: App Distribution and CI/CD
-
Section 36: More Practical Projects
-
Section 37: SwiftData and Persistence
-
Section 38: More Design Patterns
-
Section 39: More Review and Practice
-
Section 40: More Foundation Deep Dive
-
Section 41: Advanced Collections in Swift
-
Section 42: Advanced Generics Practice
-
Section 43: UIKit for Legacy and Hybrid Apps
-
Section 44: watchOS and visionOS Development Basics
-
Section 45: More Networking Patterns
-
Section 46: More Testing Practice
-
Section 47: Accessibility in Swift Apps
-
Section 48: Localization
-
Section 49: More Practical Projects Round 2
-
Section 50: Swift Charts Framework
-
Section 51: More Interview and Algorithm Practice
-
Section 52: Final Practice and Mastery
-
Section 53: Swift Compiler and Build System
-
Section 54: More Concurrency Practice
-
Section 55: App Store Guidelines and Review
-
Section 56: More Design and Architecture
249: Feature Modules and Micro-App Architecture
You've likely reached a point in your project where the "Main App" target is becoming a behemoth. When you hear senior engineers talk about "Modularization" or "Micro-App Architecture," the most common misconception I see is the belief that modularization is simply a way to organize files.
Many developers think that if they just move their PaymentViewModel and PaymentView into a separate Swift Package or Framework, they've "modularized" their app. They treat the module like a fancy folder. But here is why that's wrong: if your new PaymentModule still imports AppCore, and AppCore imports PaymentModule to initialize the flow, you haven't actually decoupled anything. You've just created a distributed monolith with slower compile times because Xcode now has to manage the overhead of a framework boundary without any of the architectural benefits.
Stop treating modules like folders; start treating them like contracts
True micro-app architecture isn't about where the code lives, but about who is allowed to know about whom. In a monolithic app, every class can see every other class. In a feature-module architecture, we enforce a strict dependency graph.
Let's take a real example: an e-commerce app. You have a CartFeature and a ProductDetailFeature. The ProductDetail screen needs to call a function to "Add to Cart." If the ProductDetailFeature imports the CartFeature directly, you're fine—until the CartFeature needs to link back to a product's detail page. Suddenly, you have a circular dependency, and the compiler will refuse to build.
The fix is to stop importing implementations and start importing Interfaces. I personally swear by the "API Module" pattern. Instead of one CartFeature module, you split it into two: CartAPI and CartImplementation.
- CartAPI: Contains only protocols and simple data models (e.g.,
protocol CartServiceProtocol { func add(product: Product) }). It has zero dependencies. - CartImplementation: Imports
CartAPIand actually does the work.
Now, the ProductDetailFeature only imports CartAPI. It doesn't know how the cart works; it just knows that something exists that conforms to CartServiceProtocol. This is the core of Micro-App architecture: features depend on abstractions, not on other features.
Managing the "Glue" with Dependency Injection
You might be wondering, "If ProductDetailFeature only knows about a protocol in CartAPI, how does it actually get a working instance of the cart service at runtime?"
This is where the Main App target comes back into play. The Main App is the "Composer." It's the only place in the entire project that is allowed to import everything. It imports both CartImplementation and ProductDetailFeature, and it "injects" the implementation into the feature.
// Inside the Main App (The Composer)
let cartService = CartService() // From CartImplementation
let productDetailVM = ProductDetailViewModel(cartService: cartService) // Injected into ProductDetailFeature
I've found that this approach does more than just fix compile times. It changes how you think. When you're forced to define a CartAPI, you're forced to think about the minimum surface area the rest of the app needs. You stop leaking internal logic and start building a system of pluggable components.
📋 Practical Task
Implementing a Decoupled Feature Interface
You are working on a travel app. Currently, the BookingFeature is tightly coupled to the UserAccountFeature, creating a circular dependency because the account page needs to show recent bookings, and the booking page needs user profile data.
Your Task: Refactor the relationship using the API Module pattern. Create the following structure in your conceptual workspace:
- UserAccountAPI: Create a protocol
UserAccountProviderwith a methodfunc getCurrentUser() -> User. - UserAccountImplementation: Create a class
UserAccountServicethat conforms toUserAccountProvider. - BookingFeature: Create a
BookingViewModelthat requires an object conforming toUserAccountProviderin its initializer. It should not importUserAccountImplementation. - Main App: Write the initialization code that instantiates
UserAccountServiceand passes it into theBookingViewModel.
Ensure that if you were to delete the UserAccountImplementation module, the BookingFeature would still compile (as long as the API module remained).
There are no comments for now.