<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by hazem habeb on Medium]]></title>
        <description><![CDATA[Stories by hazem habeb on Medium]]></description>
        <link>https://medium.com/@hazemhabeb94?source=rss-afd87fcd9114------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TqedX-DsRzwe5Odg.</url>
            <title>Stories by hazem habeb on Medium</title>
            <link>https://medium.com/@hazemhabeb94?source=rss-afd87fcd9114------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:44:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hazemhabeb94/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Reactive MVVM with Combine & Dependency Injection in SwiftUI]]></title>
            <link>https://medium.com/@hazemhabeb94/reactive-mvvm-with-combine-dependency-injection-in-swiftui-4213b13cce2d?source=rss-afd87fcd9114------2</link>
            <guid isPermaLink="false">https://medium.com/p/4213b13cce2d</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[combine]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[hazem habeb]]></dc:creator>
            <pubDate>Tue, 12 Aug 2025 08:53:06 GMT</pubDate>
            <atom:updated>2025-08-12T09:29:53.276Z</atom:updated>
            <content:encoded><![CDATA[<p><em>MVVM Like a Pro — Part 3</em></p><blockquote><em>🔗 </em><strong><em>Complete project on GitHub</em></strong><em>: </em><a href="https://github.com/Hazemhabeb/MvvmCombineDI"><em>MvvmCombineDI</em></a><em> Follow along with real, working code!</em></blockquote><h3>🚀 From Callbacks to Reactive Streams</h3><p>In Parts 1 and 2, we built solid MVVM foundations and clean navigation. Now let’s add the missing piece: <strong>reactive data flow</strong> with Combine.</p><p>Traditional iOS development chains callbacks and completion handlers, leading to:</p><ul><li>Nested closure hell</li><li>Manual UI state management</li><li>Complex error handling</li><li>Memory leaks from retain cycles</li></ul><p><strong>Combine transforms this</strong> by making your data reactive streams that SwiftUI automatically observes.</p><h3>🌊 The Power of Reactive Programming</h3><h3>Before: Imperative (Manual Updates)</h3><pre>func fetchUsers() {<br>    isLoading = true<br>    service.getUsers { result in<br>        DispatchQueue.main.async {<br>            self.isLoading = false<br>            switch result {<br>            case .success(let users): self.users = users<br>            case .failure(let error): self.errorMessage = error.localizedDescription<br>            }<br>        }<br>    }<br>}</pre><h3>After: Reactive (Automatic Updates)</h3><pre>func fetchUsers() {<br>    service.getUsers()<br>        .receive(on: DispatchQueue.main)<br>        .sink(<br>            receiveCompletion: handleCompletion,<br>            receiveValue: { self.users = $0 }<br>        )<br>        .store(in: cancelBag)<br>}</pre><p>The reactive approach is cleaner, more declarative, and handles threading automatically.</p><h3>🧩 Why Dependency Injection Matters</h3><p><strong>Dependency Injection</strong> makes your code testable and flexible:</p><h3>❌ Tight Coupling (Hard to Test)</h3><pre>class UsersViewModel: ObservableObject {<br>    private let service = UserService() // ❌ Can&#39;t mock for testing<br><br>   func loadUsers() {<br>        service.fetchUsers() // ❌ Always calls real API<br>    }<br>}</pre><h3>✅ Loose Coupling (Easy to Test)</h3><pre>class UsersViewModel: ObservableObject {<br>    private let service: UserServiceProtocol // ✅ Protocol dependency<br><br>    init(service: UserServiceProtocol) {<br>        self.service = service // ✅ Injected - can be mocked!<br>    }<br>}</pre><h3>🏗️ Building MvvmCombineDI: A Real-World Example</h3><p>Let’s build a complete team management app demonstrating these patterns.</p><blockquote><em>📁 </em><strong><em>See the complete project structure</em></strong><em>: </em><a href="https://github.com/Hazemhabeb/MvvmCombineDI"><em>GitHub Repository</em></a></blockquote><h3>📋 Data Models</h3><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/Models/User.swift">Models/User.swift</a></p><pre>struct User: Codable, Identifiable, Hashable {<br>    let id = UUID()<br>    let name: String<br>    let email: String<br>    let department: String<br>    let avatar: String<br>    var isActive: Bool<br><br>    static let samples = [<br>        User(name: &quot;Hazem Habeb&quot;, email: &quot;hazem@example.com&quot;,<br>             department: &quot;Engineering&quot;, avatar: &quot;👨‍💻&quot;, isActive: true),<br>        // ... more sample users<br>    ]<br>}</pre><p>Simple, clean data model with sample data for easy testing.</p><h3>🌐 Reactive Service Layer</h3><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/Services/UserServiceProtocol.swift">Services/UserServiceProtocol.swift</a></p><pre>protocol UserServiceProtocol {<br>    func fetchUsers() -&gt; AnyPublisher&lt;[User], NetworkError&gt;<br>    func updateUser(_ user: User) -&gt; AnyPublisher&lt;User, NetworkError&gt;<br>    func deleteUser(id: UUID) -&gt; AnyPublisher&lt;Void, NetworkError&gt;<br>}</pre><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/Services/UserService.swift">Services/UserService.swift</a></p><pre>class UserService: UserServiceProtocol {<br>    func fetchUsers() -&gt; AnyPublisher&lt;[User], NetworkError&gt; {<br>        // Simulate API call with realistic delay<br>        return Future&lt;[User], NetworkError&gt; { promise in<br>            DispatchQueue.global().asyncAfter(deadline: .now() + 1) {<br>                promise(.success(User.samples))<br>            }<br>        }<br>        .eraseToAnyPublisher()<br>    }<br><br>    // ... other methods<br>}</pre><p><strong>Key Points:</strong></p><ul><li>Protocol-based design for testability</li><li>Returns Combine publishers instead of using callbacks</li><li>Simulates real network behavior with delays</li></ul><h3>🧠 Reactive ViewModel</h3><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/ViewModels/UsersViewModel.swift">ViewModels/UsersViewModel.swift</a></p><pre>class UsersViewModel: ObservableObject {<br>    // MARK: - Published Properties (Automatic UI Updates)<br>    @Published var users: [User] = []<br>    @Published var filteredUsers: [User] = []<br>    @Published var searchText = &quot;&quot;<br>    @Published var isLoading = false<br>    @Published var errorMessage: String?<br><br>  private let userService: UserServiceProtocol<br>    private let cancelBag = CancelBag()<br><br>  init(userService: UserServiceProtocol) {<br>        self.userService = userService<br>        setupReactiveBindings() // 🔄 The magic happens here!<br>        loadUsers()<br>    }<br><br>  private func setupReactiveBindings() {<br>        // 🚀 Reactive filtering - combines all filter inputs<br>        Publishers.CombineLatest4(<br>            $users,<br>            $searchText.debounce(for: 0.3, scheduler: DispatchQueue.main),<br>            $selectedDepartment,<br>            $showActiveOnly<br>        )<br>        .map { users, searchText, department, activeOnly in<br>            self.filterUsers(users, searchText: searchText,<br>                           department: department, activeOnly: activeOnly)<br>        }<br>        .assign(to: &amp;$filteredUsers)<br>    }<br>}</pre><p><strong>🔥 What Makes This Reactive:</strong></p><ul><li>@Published properties trigger automatic UI updates</li><li>Publishers.CombineLatest4 combines multiple data streams</li><li>.debounce() prevents excessive filtering during typing</li><li>.assign(to: &amp;$filteredUsers) directly updates the filtered results</li></ul><h3>📱 SwiftUI View Layer</h3><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/Views/UsersListView.swift">Views/UsersListView.swift</a></p><pre>struct UsersListView: View {<br>    @StateObject var viewModel: UsersViewModel<br><br>    var body: some View {<br>        NavigationView {<br>            VStack {<br>                searchBar<br><br>                if viewModel.isLoading &amp;&amp; viewModel.users.isEmpty {<br>                    LoadingView()<br>                } else if viewModel.filteredUsers.isEmpty {<br>                    EmptyStateView()<br>                } else {<br>                    usersList<br>                }<br>            }<br>            .navigationTitle(&quot;Team&quot;)<br>            .refreshable {<br>                viewModel.loadUsers() // 🔄 Pull-to-refresh<br>            }<br>        }<br>    }<br><br>  private var searchBar: some View {<br>        HStack {<br>            Image(systemName: &quot;magnifyingglass&quot;)<br>            TextField(&quot;Search team members...&quot;, text: $viewModel.searchText)<br>                .textFieldStyle(RoundedBorderTextFieldStyle())<br>        }<br>        .padding()<br>    }<br>}</pre><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/Views/UserRowView.swift">Views/UserRowView.swift</a></p><pre>struct UserRowView: View {<br>    let user: User<br>    let onAction: (UserAction) -&gt; Void<br><br>    var body: some View {<br>        HStack(spacing: 12) {<br>            Text(user.avatar).font(.system(size: 32))<br><br>     VStack(alignment: .leading, spacing: 4) {<br>                HStack {<br>                    Text(user.name).font(.headline)<br>                    Spacer()<br>                    StatusBadge(isActive: user.isActive)<br>                }<br>                Text(user.email).font(.subheadline).foregroundColor(.secondary)<br>            }<br>        }<br>        .swipeActions {<br>            Button(&quot;Delete&quot;, role: .destructive) { onAction(.delete) }<br>            Button(user.isActive ? &quot;Deactivate&quot; : &quot;Activate&quot;) { onAction(.toggleStatus) }<br>        }<br>    }<br>}</pre><p><strong>Key Features:</strong></p><ul><li>Clean, focused UI components</li><li>Swipe actions for quick user management</li><li>StatusBadge component for visual status indication</li><li>Delegates user actions back to parent view</li></ul><h3>🧪 Testing with Dependency Injection</h3><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/Tests/MockServices/MockUserService.swift">Tests/MockServices/MockUserService.swift</a></p><pre>class MockUserService: UserServiceProtocol {<br>    var usersToReturn: [User] = []<br>    var shouldReturnError = false<br><br> func fetchUsers() -&gt; AnyPublisher&lt;[User], NetworkError&gt; {<br>        if shouldReturnError {<br>            return Fail(error: NetworkError.serverError)<br>                .eraseToAnyPublisher()<br>        } else {<br>            return Just(usersToReturn)<br>                .setFailureType(to: NetworkError.self)<br>                .eraseToAnyPublisher()<br>        }<br>    }<br>}</pre><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/Tests/UsersViewModelTests.swift">Tests/UsersViewModelTests.swift</a></p><pre>final class UsersViewModelTests: XCTestCase {<br>    var viewModel: UsersViewModel!<br>    var mockService: MockUserService!<br>    var cancellables: Set&lt;AnyCancellable&gt;!<br><br>  func testLoadUsersSuccess() {<br>        // Given<br>        let expectedUsers = [User.samples[0]]<br>        mockService.usersToReturn = expectedUsers<br><br>    let expectation = expectation(description: &quot;Users loaded&quot;)<br><br>    // When - Test reactive updates<br>        viewModel.$users<br>            .dropFirst()<br>            .sink { users in<br>                XCTAssertEqual(users.count, expectedUsers.count)<br>                expectation.fulfill()<br>            }<br>            .store(in: &amp;cancellables)<br><br>        // Then<br>        viewModel.loadUsers()<br>        wait(for: [expectation], timeout: 2.0)<br>    }<br><br>  func testSearchFiltering() {<br>        // Given<br>        viewModel.users = User.samples<br><br>      let expectation = expectation(description: &quot;Search applied&quot;)<br><br>        // When - Test reactive filtering<br>        viewModel.$filteredUsers<br>            .dropFirst()<br>            .sink { users in<br>                XCTAssertEqual(users.count, 1)<br>                XCTAssertEqual(users.first?.name, &quot;Hazem Habeb&quot;)<br>                expectation.fulfill()<br>            }<br>            .store(in: &amp;cancellables)<br><br>        // Then<br>        viewModel.searchText = &quot;Hazem&quot; // Triggers reactive filtering!<br>        wait(for: [expectation], timeout: 1.0)<br>    }<br>}</pre><p><strong>🧪 Testing Benefits:</strong></p><ul><li>Mock service provides predictable test data</li><li>Test reactive streams with XCTestExpectation</li><li>Verify filtering logic works correctly</li><li>No UI dependencies — pure logic testing</li></ul><h3>⚡ Advanced Combine Patterns</h3><h3>1. CancelBag for Memory Management</h3><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/Utils/CancelBag.swift">Utils/CancelBag.swift</a></p><pre>class CancelBag {<br>    var subscriptions = Set&lt;AnyCancellable&gt;()<br><br>    func cancel() {<br>        subscriptions.removeAll()<br>    }<br>}<br><br>extension AnyCancellable {<br>    func store(in cancelBag: CancelBag) {<br>        cancelBag.subscriptions.insert(self)<br>    }<br>}</pre><p><strong>Why CancelBag?</strong></p><ul><li>Cleaner than Set&lt;AnyCancellable&gt;</li><li>Automatic cleanup on deinit</li><li>Easy to cancel all subscriptions</li></ul><h3>2. Debouncing User Input</h3><pre>$searchText<br>    .debounce(for: 0.3, scheduler: DispatchQueue.main)<br>    .removeDuplicates()<br>    .sink { searchText in<br>        // Only fires 300ms after user stops typing<br>        self.performSearch(searchText)<br>    }<br>    .store(in: cancelBag)</pre><h3>3. Combining Multiple Publishers</h3><pre>Publishers.CombineLatest4(<br>    $users,<br>    $searchText.debounce(for: 0.3, scheduler: DispatchQueue.main),<br>    $selectedDepartment,<br>    $showActiveOnly<br>)<br>.map { users, searchText, department, activeOnly in<br>    // Combines all filtering criteria into one stream<br>    return self.filterUsers(users, searchText: searchText,<br>                          department: department, activeOnly: activeOnly)<br>}<br>.assign(to: &amp;$filteredUsers)</pre><h3>💉 Dependency Injection Patterns</h3><h3>Manual DI Container</h3><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/DI/DIContainer.swift">DI/DIContainer.swift</a></p><pre>class DIContainer: ObservableObject {<br>    lazy var userService: UserServiceProtocol = UserService()<br>    // Add more services as your app grows<br>}</pre><h3>Environment-Based DI</h3><pre>struct UserServiceKey: EnvironmentKey {<br>    static let defaultValue: UserServiceProtocol = UserService()<br>}<br><br>extension EnvironmentValues {<br>    var userService: UserServiceProtocol {<br>        get { self[UserServiceKey.self] }<br>        set { self[UserServiceKey.self] = newValue }<br>    }<br>}</pre><h3>App Integration</h3><p><strong>File</strong>: <a href="https://github.com/Hazemhabeb/MvvmCombineDI/blob/main/MvvmCombineDI/App/MvvmCombineDIApp.swift">App/MvvmCombineDI.swift</a></p><pre>@main<br>struct TeamManagerApp: App {<br>  let container = DIContainer()<br><br>  var body: some Scene {<br>        WindowGroup {<br>            ContentView()<br>                .environmentObject(container) // 💉 Inject dependencies<br>        }<br>    }<br>}</pre><h3>📊 Architecture Flow</h3><p>Here’s how everything works together:</p><pre>User Types → @Published searchText → Debounced Publisher → CombineLatest4 → Filtered Results → UI Update<br>     ↓              ↓                      ↓                    ↓              ↓           ↓<br>   SwiftUI      ViewModel           Combine Pipeline        Filter Logic    @Published   Auto-Refresh</pre><p><strong>🔄 The Reactive Loop:</strong></p><ol><li>User types in search field</li><li>@Published searchText emits new value</li><li>.debounce() waits for user to stop typing</li><li>CombineLatest4 combines with other filters</li><li>.map() applies filtering logic</li><li>.assign(to: &amp;$filteredUsers) updates UI automatically</li><li>SwiftUI re-renders with new data</li></ol><h3>🎯 Key Benefits Achieved</h3><h3>✅ Automatic UI Updates</h3><pre>@Published var users: [User] = [] // ← Change this<br>// SwiftUI automatically updates ↑</pre><h3>✅ Declarative Data Flow</h3><pre>// Instead of manual if/else chains:<br>$searchText<br>    .debounce(for: 0.3, scheduler: DispatchQueue.main)<br>    .map(filterUsers)<br>    .assign(to: &amp;$filteredUsers)</pre><h3>✅ Easy Testing</h3><pre>// Inject mock service - test pure logic<br>let viewModel = UsersViewModel(userService: MockUserService())</pre><h3>✅ Memory Safety</h3><pre>// Automatic cleanup with CancelBag<br>.store(in: cancelBag)</pre><h3>📚 What You’ve Learned</h3><p><strong>🔄 Reactive Programming:</strong></p><ul><li>@Published for automatic UI updates</li><li>Publishers for data streams</li><li>Debouncing for performance</li><li>Combining multiple data sources</li></ul><p><strong>💉 Dependency Injection:</strong></p><ul><li>Protocol-based services</li><li>Easy mocking for tests</li><li>Flexible architecture</li><li>Loose coupling</li></ul><p><strong>🏗️ Clean Architecture:</strong></p><ul><li>Separated concerns</li><li>Testable components</li><li>Scalable patterns</li><li>Production-ready code</li></ul><h3>🔜 Coming Up in Part 4</h3><p>In our final article, we’ll explore <strong>The Composable Architecture (TCA)</strong> and compare it with MVVM:</p><ul><li>When MVVM reaches its limits</li><li>Unidirectional data flow with TCA</li><li>Performance comparison: MVVM vs TCA</li><li>Migration strategies for large apps</li></ul><p><strong>Which architecture will win for complex SwiftUI applications?</strong> 🏆</p><blockquote><em>💡 </em><strong><em>Try it yourself!</em></strong><em> Clone the </em><a href="https://github.com/Hazemhabeb/MvvmCombineDI"><em>GitHub repository</em></a><em>, experiment with the code, and share your improvements!</em></blockquote><p><em>Questions about reactive MVVM or want to share your implementation? Drop a comment below! .</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4213b13cce2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVVM + Coordinator: The Secret to Clean Navigation in SwiftUI]]></title>
            <link>https://medium.com/@hazemhabeb94/mvvm-coordinator-the-secret-to-clean-navigation-in-swiftui-49b28307611f?source=rss-afd87fcd9114------2</link>
            <guid isPermaLink="false">https://medium.com/p/49b28307611f</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mvvm-architecture]]></category>
            <category><![CDATA[mvvm]]></category>
            <dc:creator><![CDATA[hazem habeb]]></dc:creator>
            <pubDate>Wed, 06 Aug 2025 21:07:41 GMT</pubDate>
            <atom:updated>2025-08-06T21:08:58.261Z</atom:updated>
            <content:encoded><![CDATA[<h3>MVVM + Coordinator: The Secret to Clean Navigation (part 2)</h3><h4><em>MVVM Like a Pro — Part 2</em></h4><h3>🚀 Why Basic MVVM Isn’t Enough</h3><p>MVVM does a great job separating UI from business logic. But as your SwiftUI app grows, you’ll face a common problem: <strong>Where should navigation logic live?</strong></p><p>Putting navigation in Views creates tight coupling. Putting it in ViewModels makes them hard to test and breaks the single responsibility principle. That’s where the <strong>Coordinator Pattern</strong> becomes your best friend.</p><h3>🧭 What is a Coordinator?</h3><p>A <strong>Coordinator</strong> is a dedicated object that owns all navigation decisions in your app. Think of it as a traffic controller for your screens.</p><p><strong>Benefits:</strong></p><ul><li>✅ Centralized navigation logic</li><li>✅ ViewModels stay focused on data logic</li><li>✅ Views remain simple and declarative</li><li>✅ Easy to test navigation flows</li><li>✅ Better code reusability</li></ul><h3>🤔 NavigationLink vs Coordinator: When to Use What?</h3><p><strong>Use NavigationLink when:</strong></p><ul><li>Simple, static navigation</li><li>Prototyping or small apps</li><li>One-way navigation flows</li></ul><p><strong>Use Coordinator when:</strong></p><ul><li>Complex navigation logic</li><li>Dynamic flows based on business rules</li><li>Multiple entry points to screens</li><li>Need to test navigation</li><li>Apps with deep linking</li></ul><h3>🛠 Building a Real-World Example</h3><p>Let’s build a user management flow: Home → User Detail → Edit Profile</p><h3>Model Layer</h3><pre>struct User: Hashable {<br>    let id: UUID = UUID()<br>    let name: String<br>    let email: String<br>    let avatar: String<br>}<br><br>enum NavigationError: Error, LocalizedError {<br>    case invalidUser<br>    case networkError<br>    <br>    var errorDescription: String? {<br>        switch self {<br>        case .invalidUser: return &quot;Invalid user data&quot;<br>        case .networkError: return &quot;Network connection failed&quot;<br>        }<br>    }<br>}</pre><h3>Coordinator Protocol &amp; Implementation</h3><pre>import SwiftUI<br><br>protocol Coordinator: ObservableObject {<br>    associatedtype Route: Hashable<br>    var path: NavigationPath { get set }<br>    func navigate(to route: Route)<br>    func pop()<br>    func popToRoot()<br>}<br><br>enum AppRoute: Hashable {<br>    case userDetail(User)<br>    case editProfile(User)<br>    case settings<br>}<br><br>class AppCoordinator: Coordinator {<br>    @Published var path = NavigationPath()<br>    @Published var alertMessage: String?<br>    @Published var showAlert = false<br>    <br>    func navigate(to route: AppRoute) {<br>        path.append(route)<br>    }<br>    <br>    func pop() {<br>        guard !path.isEmpty else { return }<br>        path.removeLast()<br>    }<br>    <br>    func popToRoot() {<br>        path.removeLast(path.count)<br>    }<br>    <br>    func handleError(_ error: NavigationError) {<br>        alertMessage = error.localizedDescription<br>        showAlert = true<br>    }<br>}</pre><h3>ViewModel Layer</h3><pre>import Foundation<br><br>class HomeViewModel: ObservableObject {<br>    @Published var users: [User] = []<br>    @Published var isLoading = false<br>    <br>    init() {<br>        loadUsers()<br>    }<br>    <br>    private func loadUsers() {<br>        isLoading = true<br>        // Simulate API call<br>        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {<br>            self.users = [<br>                User(name: &quot;Hazem Habeb&quot;, email: &quot;hazem@example.com&quot;, avatar: &quot;👨‍💻&quot;),<br>                User(name: &quot;Sarah Johnson&quot;, email: &quot;sarah@example.com&quot;, avatar: &quot;👩‍🎨&quot;),<br>                User(name: &quot;Mike Chen&quot;, email: &quot;mike@example.com&quot;, avatar: &quot;👨‍🚀&quot;)<br>            ]<br>            self.isLoading = false<br>        }<br>    }<br>    <br>    func refreshUsers() {<br>        loadUsers()<br>    }<br>}</pre><h3>View Layer</h3><pre>import SwiftUI<br><br>struct HomeView: View {<br>    @ObservedObject var viewModel: HomeViewModel<br>    @ObservedObject var coordinator: AppCoordinator<br>    <br>    var body: some View {<br>        VStack(spacing: 20) {<br>            headerView<br>            <br>            if viewModel.isLoading {<br>                ProgressView(&quot;Loading users...&quot;)<br>                    .frame(maxHeight: .infinity)<br>            } else {<br>                usersList<br>            }<br>        }<br>        .navigationTitle(&quot;Team&quot;)<br>        .toolbar {<br>            toolbarButtons<br>        }<br>        .alert(&quot;Error&quot;, isPresented: $coordinator.showAlert) {<br>            Button(&quot;OK&quot;) { }<br>        } message: {<br>            Text(coordinator.alertMessage ?? &quot;Unknown error&quot;)<br>        }<br>    }<br>    <br>    private var headerView: some View {<br>        VStack {<br>            Text(&quot;👥&quot;)<br>                .font(.system(size: 60))<br>            Text(&quot;Team Members&quot;)<br>                .font(.title2)<br>                .fontWeight(.semibold)<br>        }<br>        .padding()<br>    }<br>    <br>    private var usersList: some View {<br>        LazyVStack(spacing: 12) {<br>            ForEach(viewModel.users, id: \.id) { user in<br>                UserRowView(user: user) {<br>                    coordinator.navigate(to: .userDetail(user))<br>                }<br>            }<br>        }<br>        .padding(.horizontal)<br>    }<br>    <br>    private var toolbarButtons: some ToolbarContent {<br>        ToolbarItemGroup(placement: .navigationBarTrailing) {<br>            Button {<br>                coordinator.navigate(to: .settings)<br>            } label: {<br>                Image(systemName: &quot;gear&quot;)<br>            }<br>            <br>            Button {<br>                viewModel.refreshUsers()<br>            } label: {<br>                Image(systemName: &quot;arrow.clockwise&quot;)<br>            }<br>        }<br>    }<br>}<br><br><br>struct UserRowView: View {<br>    let user: User<br>    let onTap: () -&gt; Void<br>    <br>    var body: some View {<br>        Button(action: onTap) {<br>            HStack(spacing: 16) {<br>                Text(user.avatar)<br>                    .font(.system(size: 40))<br>                <br>                VStack(alignment: .leading, spacing: 4) {<br>                    Text(user.name)<br>                        .font(.headline)<br>                        .foregroundColor(.primary)<br>                    <br>                    Text(user.email)<br>                        .font(.subheadline)<br>                        .foregroundColor(.secondary)<br>                }<br>                <br>                Spacer()<br>                <br>                Image(systemName: &quot;chevron.right&quot;)<br>                    .foregroundColor(.secondary)<br>                    .font(.caption)<br>            }<br>            .padding()<br>            .background(Color(.systemGray6))<br>            .cornerRadius(12)<br>        }<br>        .buttonStyle(PlainButtonStyle())<br>    }<br>}</pre><h3>Detail Views</h3><pre>struct UserDetailView: View {<br>    let user: User<br>    @ObservedObject var coordinator: AppCoordinator<br>    <br>    var body: some View {<br>        ScrollView {<br>            VStack(spacing: 24) {<br>                profileHeader<br>                userInfo<br>                actionButtons<br>            }<br>            .padding()<br>        }<br>        .navigationTitle(&quot;Profile&quot;)<br>        .navigationBarTitleDisplayMode(.inline)<br>    }<br>    <br>    private var profileHeader: some View {<br>        VStack(spacing: 16) {<br>            Text(user.avatar)<br>                .font(.system(size: 80))<br>            <br>            Text(user.name)<br>                .font(.title)<br>                .fontWeight(.bold)<br>        }<br>    }<br>    <br>    private var userInfo: some View {<br>        VStack(alignment: .leading, spacing: 16) {<br>            InfoRow(title: &quot;Email&quot;, value: user.email, icon: &quot;envelope&quot;)<br>            InfoRow(title: &quot;ID&quot;, value: user.id.uuidString.prefix(8) + &quot;...&quot;, icon: &quot;number&quot;)<br>        }<br>        .padding()<br>        .background(Color(.systemGray6))<br>        .cornerRadius(12)<br>    }<br>    <br>    private var actionButtons: some View {<br>        VStack(spacing: 12) {<br>            Button {<br>                coordinator.navigate(to: .editProfile(user))<br>            } label: {<br>                HStack {<br>                    Image(systemName: &quot;pencil&quot;)<br>                    Text(&quot;Edit Profile&quot;)<br>                }<br>                .frame(maxWidth: .infinity)<br>                .padding()<br>                .background(Color.blue)<br>                .foregroundColor(.white)<br>                .cornerRadius(10)<br>            }<br>            <br>            Button {<br>                coordinator.pop()<br>            } label: {<br>                HStack {<br>                    Image(systemName: &quot;arrow.left&quot;)<br>                    Text(&quot;Back to Team&quot;)<br>                }<br>                .frame(maxWidth: .infinity)<br>                .padding()<br>                .background(Color(.systemGray5))<br>                .foregroundColor(.primary)<br>                .cornerRadius(10)<br>            }<br>        }<br>    }<br>}<br><br><br>struct InfoRow: View {<br>    let title: String<br>    let value: String<br>    let icon: String<br>    <br>    var body: some View {<br>        HStack {<br>            Image(systemName: icon)<br>                .foregroundColor(.blue)<br>                .frame(width: 20)<br>            <br>            Text(title)<br>                .fontWeight(.medium)<br>            <br>            Spacer()<br>            <br>            Text(value)<br>                .foregroundColor(.secondary)<br>        }<br>    }<br>}<br><br>struct EditProfileView: View {<br>    let user: User<br>    @ObservedObject var coordinator: AppCoordinator<br>    @State private var editedName: String<br>    @State private var editedEmail: String<br>    <br>    init(user: User, coordinator: AppCoordinator) {<br>        self.user = user<br>        self.coordinator = coordinator<br>        self._editedName = State(initialValue: user.name)<br>        self._editedEmail = State(initialValue: user.email)<br>    }<br>    <br>    var body: some View {<br>        NavigationView {<br>            Form {<br>                Section(&quot;Profile Information&quot;) {<br>                    TextField(&quot;Name&quot;, text: $editedName)<br>                    TextField(&quot;Email&quot;, text: $editedEmail)<br>                        .keyboardType(.emailAddress)<br>                }<br>            }<br>            .navigationTitle(&quot;Edit Profile&quot;)<br>            .navigationBarTitleDisplayMode(.inline)<br>            .toolbar {<br>                ToolbarItem(placement: .navigationBarLeading) {<br>                    Button(&quot;Cancel&quot;) {<br>                        coordinator.pop()<br>                    }<br>                }<br>                <br>                ToolbarItem(placement: .navigationBarTrailing) {<br>                    Button(&quot;Save&quot;) {<br>                        // Handle save logic here<br>                        coordinator.pop()<br>                    }<br>                    .fontWeight(.semibold)<br>                }<br>            }<br>        }<br>    }<br>}<br><br>struct SettingsView: View {<br>    @ObservedObject var coordinator: AppCoordinator<br>    <br>    var body: some View {<br>        List {<br>            Section(&quot;App Settings&quot;) {<br>                HStack {<br>                    Image(systemName: &quot;bell&quot;)<br>                    Text(&quot;Notifications&quot;)<br>                }<br>                <br>                HStack {<br>                    Image(systemName: &quot;moon&quot;)<br>                    Text(&quot;Dark Mode&quot;)<br>                }<br>            }<br>        }<br>        .navigationTitle(&quot;Settings&quot;)<br>    }<br>}</pre><h3>Main App Entry Point</h3><pre>import SwiftUI<br><br>@main<br>struct MVVMCoordinatorApp: App {<br>    @StateObject private var coordinator = AppCoordinator()<br>    <br>    var body: some Scene {<br>        WindowGroup {<br>            NavigationStack(path: $coordinator.path) {<br>                HomeView(<br>                    viewModel: HomeViewModel(),<br>                    coordinator: coordinator<br>                )<br>                .navigationDestination(for: AppRoute.self) { route in<br>                    destinationView(for: route)<br>                }<br>            }<br>        }<br>    }<br>    <br>    @ViewBuilder<br>    private func destinationView(for route: AppRoute) -&gt; some View {<br>        switch route {<br>        case .userDetail(let user):<br>            UserDetailView(user: user, coordinator: coordinator)<br>            <br>        case .editProfile(let user):<br>            EditProfileView(user: user, coordinator: coordinator)<br>            <br>        case .settings:<br>            SettingsView(coordinator: coordinator)<br>        }<br>    }<br>}</pre><h3>🧪 Testing Your Coordinator</h3><p>One of the biggest advantages of coordinators is testability:</p><pre>import XCTest<br>@testable import YourApp<br><br>class AppCoordinatorTests: XCTestCase {<br>    var coordinator: AppCoordinator!<br>    <br>    override func setUp() {<br>        coordinator = AppCoordinator()<br>    }<br>    <br>    func testNavigationToUserDetail() {<br>        let user = User(name: &quot;Test User&quot;, email: &quot;test@example.com&quot;, avatar: &quot;👤&quot;)<br>        <br>        coordinator.navigate(to: .userDetail(user))<br>        <br>        XCTAssertEqual(coordinator.path.count, 1)<br>    }<br>    <br>    func testNavigationFlow() {<br>        let user = User(name: &quot;Test User&quot;, email: &quot;test@example.com&quot;, avatar: &quot;👤&quot;)<br>        <br>        // Navigate through the flow<br>        coordinator.navigate(to: .userDetail(user))<br>        coordinator.navigate(to: .editProfile(user))<br>        <br>        XCTAssertEqual(coordinator.path.count, 2)<br>        <br>        // Pop back<br>        coordinator.pop()<br>        <br>        XCTAssertEqual(coordinator.path.count, 1)<br>    }<br>    <br>    func testPopToRoot() {<br>        let user = User(name: &quot;Test User&quot;, email: &quot;test@example.com&quot;, avatar: &quot;👤&quot;)<br>        <br>        coordinator.navigate(to: .userDetail(user))<br>        coordinator.navigate(to: .editProfile(user))<br>        coordinator.navigate(to: .settings)<br>        <br>        coordinator.popToRoot()<br>        <br>        XCTAssertEqual(coordinator.path.count, 0)<br>    }<br>}<br><br>// Mock Coordinator for testing ViewModels<br>class MockCoordinator: AppCoordinator {<br>    var navigationCallCount = 0<br>    var lastRoute: AppRoute?<br>    <br>    override func navigate(to route: AppRoute) {<br>        navigationCallCount += 1<br>        lastRoute = route<br>        // Don&#39;t call super to avoid actual navigation in tests<br>    }<br>}</pre><h3>⚠️ Common MVVM-C Mistakes to Avoid</h3><h3>❌ Don’t Do This</h3><pre>// Putting navigation logic in ViewModel<br>class HomeViewModel: ObservableObject {<br>    @Published var shouldShowDetail = false<br>    <br>    func showUserDetail() {<br>        shouldShowDetail = true // ❌ ViewModel shouldn&#39;t control navigation<br>    }<br>}<br><br>// Tight coupling between Views<br>struct HomeView: View {<br>    var body: some View {<br>        NavigationLink(&quot;Show Detail&quot;) {<br>            UserDetailView() // ❌ Hard-coded navigation<br>        }<br>    }<br>}</pre><h3>✅ Do This Instead</h3><pre>// Clean separation of concerns<br>class HomeViewModel: ObservableObject {<br>    @Published var users: [User] = []<br>    <br>    func selectUser(_ user: User) -&gt; User {<br>        return user // ✅ ViewModel just returns data<br>    }<br>}<br><br>struct HomeView: View {<br>    @ObservedObject var coordinator: AppCoordinator<br>    <br>    var body: some View {<br>        Button(&quot;Show Detail&quot;) {<br>            coordinator.navigate(to: .userDetail(user)) // ✅ Coordinator handles navigation<br>        }<br>    }<br>}</pre><h3>🎯 Architecture Flow</h3><p>Here’s how the pieces work together:</p><pre>User Interaction → View → Coordinator → Navigation → New View<br>       ↑             ↓         ↓           ↓          ↓<br>   Button Tap    Delegates  Updates   NavigationPath  Renders<br>                Navigation  to Stack   gets updated   DetailView</pre><p><strong>Key Points:</strong></p><ul><li>Views are dumb and delegate navigation decisions</li><li>Coordinator owns the navigation state</li><li>ViewModels focus purely on business logic</li><li>Easy to test each component in isolation</li></ul><h3>🧠 Why This Architecture Wins</h3><p><strong>✅ Single Responsibility</strong>: Each layer has one job</p><ul><li>Views handle UI and layout</li><li>ViewModels manage business logic and state</li><li>Coordinators control navigation flow</li></ul><p><strong>✅ Testability</strong>: Mock coordinators make testing ViewModels trivial</p><p><strong>✅ Scalability</strong>: Adding new screens is just adding new routes</p><p><strong>✅ Flexibility</strong>: Easy to change navigation logic without touching Views</p><p><strong>✅ Reusability</strong>: Views can be reused with different coordinators</p><h3>🚀 Advanced Patterns</h3><h3>Deep Linking Support</h3><pre>extension AppCoordinator {<br>    func handleDeepLink(_ url: URL) {<br>        guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),<br>              let path = components.path.split(separator: &quot;/&quot;).map(String.init).first else {<br>            return<br>        }<br>        <br>        switch path {<br>        case &quot;user&quot;:<br>            if let userId = components.queryItems?.first(where: { $0.name == &quot;id&quot; })?.value {<br>                // Navigate to user detail<br>                // coordinator.navigate(to: .userDetail(user))<br>            }<br>        default:<br>            break<br>        }<br>    }<br>}</pre><h3>Modal Presentation</h3><pre>class AppCoordinator: Coordinator {<br>    @Published var presentedSheet: AppRoute?<br>    <br>    func presentSheet(_ route: AppRoute) {<br>        presentedSheet = route<br>    }<br>    <br>    func dismissSheet() {<br>        presentedSheet = nil<br>    }<br>}</pre><h3>🔜 Coming Up in Part 3</h3><p>In the next article, we’ll supercharge our MVVM-C architecture with <strong>Combine and Dependency Injection</strong>:</p><ul><li>Replace closures with reactive publishers</li><li>Handle async operations cleanly</li><li>Mock services for bulletproof testing</li><li>CancelBag patterns for memory management</li></ul><p>Follow along to master reactive MVVM in SwiftUI! 🚀</p><p><em>Have questions about coordinators or want to share your implementation? Drop a comment below! 👇</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49b28307611f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✍️ How to Use MVVM Like a Pro in iOS ( part 1 )]]></title>
            <link>https://medium.com/@hazemhabeb94/%EF%B8%8F-how-to-use-mvvm-like-a-pro-in-ios-part-1-2eb1ac60131d?source=rss-afd87fcd9114------2</link>
            <guid isPermaLink="false">https://medium.com/p/2eb1ac60131d</guid>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[mvvm-architecture]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[hazem habeb]]></dc:creator>
            <pubDate>Wed, 06 Aug 2025 20:44:59 GMT</pubDate>
            <atom:updated>2025-08-06T20:44:59.298Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>If you’ve ever felt confused by MVVM or struggled to apply it correctly in SwiftUI, you’re not alone. In this article, I’ll break down MVVM in the most practical way possible — from simple architecture theory to a real-world, testable SwiftUI implementation. You’ll walk away with a solid understanding of how to build clean, scalable iOS apps using MVVM like a pro — with loading states, error handling, and more.</em></blockquote><h3>🧠 What is MVVM?</h3><p>MVVM stands for:</p><ul><li><strong>Model</strong> — Your app’s data (structs, networking results, database objects, etc.)</li><li><strong>ViewModel</strong> — A bridge between your model and view. It contains UI logic.</li><li><strong>View</strong> — Your SwiftUI view that observes and displays data from the ViewModel.</li></ul><p>MVVM helps separate responsibilities and makes your app easier to test, scale, and maintain.</p><h3>💡 Simple MVVM in SwiftUI</h3><p>Let’s build a tiny app that shows user info using MVVM.</p><h3>Step 1: Define the Model</h3><pre>struct User {<br>    let name: String<br>    let email: String<br>}</pre><h3>Step 2: Create the ViewModel</h3><pre>import Foundation<br><br>class UserViewModel: ObservableObject {<br>    @Published var displayName: String = &quot;&quot;<br>    @Published var displayEmail: String = &quot;&quot;<br>    @Published var isLoading: Bool = false<br>    private let user: User<br><br>    init(user: User) {<br>        self.user = user<br>        loadUserData()<br>    }<br><br>   func loadUserData() {<br>        isLoading = true<br>        // Simulate loading delay<br>        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {<br>            self.displayName = &quot;👤 \(self.user.name)&quot;<br>            self.displayEmail = &quot;📧 \(self.user.email)&quot;<br>            self.isLoading = false<br>        }<br>    }<br>}</pre><h3>Step 3: Build the View</h3><pre>import SwiftUI<br><br>struct UserView: View {<br>    @ObservedObject var viewModel: UserViewModel<br><br>   var body: some View {<br>        VStack(spacing: 16) {<br>            if viewModel.isLoading {<br>                ProgressView(&quot;Loading...&quot;)<br>            } else {<br>                Text(viewModel.displayName)<br>                    .font(.title)<br>                Text(viewModel.displayEmail)<br>                    .font(.subheadline)<br>                    .foregroundColor(.gray)<br>            }<br>        }<br>        .padding()<br>    }<br>}</pre><h3>Step 4: Add the Entry Point</h3><pre>@main<br>struct MVVMProApp: App {<br>    var body: some Scene {<br>        WindowGroup {<br>            let user = User(name: &quot;John&quot;, email: &quot;john@example.com&quot;)<br>            let viewModel = UserViewModel(user: user)<br>            UserView(viewModel: viewModel)<br>        }<br>    }<br>}</pre><h3>✅ Result</h3><p>You now have a clean MVVM setup using SwiftUI with:</p><ul><li>Separation of logic</li><li>Reactive UI updates</li><li>A simulated async loading state</li></ul><h3>⚠️ MVVM Pitfalls to Dodge Like a Pro</h3><p>❌ Putting formatting or logic directly in the View<br>❌ Making ViewModel too fat with unrelated responsibilities<br>❌ Letting the View talk directly to the Model</p><p>✅ Always keep each layer focused and testable.</p><h3>🧪 Bonus: Unit Test Your ViewModel</h3><p>Testing MVVM is easy since the logic is separate from the UI.</p><pre>import XCTest<br>@testable import YourApp<br><br>class UserViewModelTests: XCTestCase {<br>    func testUserDataFormatting() {<br>        let user = User(name: &quot;John&quot;, email: &quot;john@test.com&quot;)<br>        let viewModel = UserViewModel(user: user)<br>        XCTAssertEqual(viewModel.displayName, &quot;👤 John&quot;)<br>        XCTAssertEqual(viewModel.displayEmail, &quot;📧 john@test.com&quot;)<br>    }<br>}</pre><h3>🔚 Final Thoughts</h3><p>This is just the beginning of advanced MVVM in SwiftUI. In the next parts, we’ll explore:</p><ul><li>Coordinators for navigation (MVVM-C)</li><li>Dependency injection for testability</li><li>Combine-based MVVM pipelines</li><li>Scalable architecture for real-world iOS apps</li></ul><p>👋 <strong>Follow me for the next article: “MVVM + Coordinator: Scalable Navigation in SwiftUI.”</strong></p><p>Have questions? Drop them in the comments</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2eb1ac60131d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL vs REST: A Real Talk for iOS Developers]]></title>
            <link>https://medium.com/@hazemhabeb94/graphql-vs-rest-a-real-talk-for-ios-developers-b3be5e364014?source=rss-afd87fcd9114------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3be5e364014</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-development]]></category>
            <dc:creator><![CDATA[hazem habeb]]></dc:creator>
            <pubDate>Sun, 25 May 2025 21:11:32 GMT</pubDate>
            <atom:updated>2025-05-25T21:11:32.781Z</atom:updated>
            <content:encoded><![CDATA[<h3>Let’s Talk APIs — and a Bit of Frustration</h3><p>Picture this.</p><p>I’m building an iOS app with a tight deadline. I need to fetch a user’s profile, their posts, and some comments. The backend team gives me three REST endpoints:</p><ul><li>/users/{id}</li><li>/users/{id}/posts</li><li>/posts/{id}/comments</li></ul><p>So now I’m chaining network calls, manually handling errors, and piecing data together in Swift. The code works, but it’s messy. And I haven’t even touched the UI yet.</p><p>There <em>had</em> to be a better way.</p><p>That’s when I found GraphQL.</p><h3>REST: The Classic (and Sometimes Painful) Way</h3><p>REST has been the default for years. It’s simple, clear, and predictable. But when your app grows — especially with relational or nested data — it starts to become a hassle.</p><p>Here’s how a typical flow looks in REST:</p><ul><li>Call /users/123 → get the user</li><li>Call /users/123/posts → get their posts</li><li>Maybe call /posts/456/comments → get related comments</li></ul><p>You end up writing boilerplate code, parsing large JSON responses, and doing more work than you should.</p><h3>🟢 REST Pros:</h3><ul><li>Easy to understand</li><li>Works great for small apps or flat data</li><li>Tons of tools like Alamofire, Moya, and URLSession</li></ul><h3>🔴 REST Cons:</h3><ul><li><strong>Over-fetching</strong>: Getting data you don’t need</li><li><strong>Under-fetching</strong>: Needing to make more calls to get related data</li><li><strong>Versioning hell</strong>: /api/v2, /v3, etc.</li></ul><p>I remember working with a REST API that returned a giant JSON blob for a simple user detail screen. 80% of the data went unused — and it slowed everything down.</p><h3>GraphQL: Ask for Exactly What You Need</h3><p>GraphQL flips the model. Instead of multiple endpoints, it gives you <em>one</em> — and you tell it exactly what data you want.</p><p>You write a query like this:</p><pre>query GetUser($id: ID!) {<br>  user(id: $id) {<br>    name<br>    posts {<br>      title<br>    }<br>  }<br>}</pre><p>And the response? Only the fields you asked for:</p><pre>{<br>  &quot;data&quot;: {<br>    &quot;user&quot;: {<br>      &quot;name&quot;: &quot;Jane Doe&quot;,<br>      &quot;posts&quot;: [<br>        { &quot;title&quot;: &quot;My First Post&quot; },<br>        { &quot;title&quot;: &quot;iOS Tips&quot; }<br>      ]<br>    }<br>  }<br>}</pre><h3>🟢 GraphQL Pros:</h3><ul><li>One query = one network call</li><li>No over-fetching or under-fetching</li><li>Strongly typed responses (Apollo generates Swift types!)</li><li>Easy to evolve — no versioning mess</li></ul><h3>🔴 GraphQL Cons:</h3><ul><li>Takes a bit to learn (queries, fragments, etc.)</li><li>Setup with Apollo or other tools can be tricky</li><li>Backend needs to support it — not always in your control</li></ul><p>The first time I used GraphQL on an iOS project, I cut my networking code in half. Everything just felt… cleaner.</p><h3><strong>REST vs GraphQL — Side by Side</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ie7Qem5Bk5Q5lHXz5vIuEw.png" /></figure><h3>When to Use REST</h3><p>REST is still totally fine in a lot of cases:</p><ul><li>Simple apps with flat data (e.g., weather, todo lists)</li><li>Legacy backends that aren’t going anywhere</li><li>Teams that don’t have the time to learn new tooling</li></ul><p>I’ve used REST for smaller projects and had zero regrets. If it does the job — stick with it.</p><h3>When to Use GraphQL</h3><p>GraphQL shines when:</p><ul><li>You’re dealing with <strong>complex or nested data</strong></li><li>You want <strong>fewer network calls</strong></li><li>You’re starting fresh with a backend that supports GraphQL</li></ul><p>It’s especially useful in social, e-commerce, and content-heavy apps — where you need fine control over what you show, when, and how fast.</p><h3>A Heads-Up: The Learning Curve Is Real</h3><p>GraphQL is powerful, but it’s not magic. You’ll need to:</p><ul><li>Learn how to write queries (and fragments)</li><li>Set up codegen and schema syncing in Apollo iOS</li><li>Understand the backend schema</li></ul><p>My first GraphQL project felt bumpy. I spent hours debugging a query that was fetching way too much data. But once I got comfortable, I didn’t want to go back.</p><h3>Final Thoughts</h3><p>If you’re starting a new feature and your backend supports GraphQL — try it.</p><p>Start small. Use it on one screen. Get familiar with Apollo and see how your networking code improves. It might feel strange at first, but it pays off.</p><p>And if you’re still using REST? That’s fine too. Just know there’s another tool in your toolbox when the time is right.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3be5e364014" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>