<?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 Rogerio Pires on Medium]]></title>
        <description><![CDATA[Stories by Rogerio Pires on Medium]]></description>
        <link>https://medium.com/@rogeriocpires_128?source=rss-db0ea3ae029c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RqHuKGJUg6fyAZnVFceLyg.jpeg</url>
            <title>Stories by Rogerio Pires on Medium</title>
            <link>https://medium.com/@rogeriocpires_128?source=rss-db0ea3ae029c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:31:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rogeriocpires_128/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[Implementing MVVM in SwiftUI with Organized Folder Structures]]></title>
            <link>https://medium.com/@rogeriocpires_128/implementing-mvvm-in-swiftui-with-organized-folder-structures-bc86845eead8?source=rss-db0ea3ae029c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc86845eead8</guid>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mvvm-architecture]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Rogerio Pires]]></dc:creator>
            <pubDate>Sat, 06 Jul 2024 21:40:38 GMT</pubDate>
            <atom:updated>2024-07-06T21:40:38.111Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H0zHKtoEyobDrWFPA3Ql4A.jpeg" /></figure><h3>MVVM (Model-View-ViewModel) Design Pattern in SwiftUI</h3><p>MVVM is a design pattern that separates business logic from the user interface, making the code easier to maintain and scale. In SwiftUI, MVVM is particularly useful due to the declarative nature of the framework. Let’s understand each component:</p><ul><li><strong>Model</strong>: Represents the data and business logic. These are the structures that contain the data and business rules.</li><li><strong>View</strong>: The user interface. In SwiftUI, views are declarative and described through structures that conform to the view protocol.</li><li><strong>ViewModel</strong>: Acts as a bridge between the Model and the View. It contains presentation logic and transforms Model data into something the View can display.</li></ul><h3>Folder Structure by Project Size</h3><p>(Note: The following structures can be seen in detail in the provided project examples above for small, medium, and large projects with features.)</p><h3>Small Project</h3><p><strong>Folder Structure:</strong></p><pre>MyApp/<br>├── MyAppApp.swift<br>├── Models/<br>│   └── User.swift<br>├── Views/<br>│   ├── ContentView.swift<br>│   └── UserDetailView.swift<br>├── ViewModels/<br>│   └── UserViewModel.swift<br>└── Resources/<br>    ├── Assets.xcassets</pre><h3>Medium Project with Features</h3><p><strong>Folder Structure:</strong></p><pre>MyApp/<br>├── MyAppApp.swift<br>├── Features/<br>│   ├── User/<br>│   │   ├── Models/<br>│   │   │   └── User.swift<br>│   │   ├── Views/<br>│   │   │   ├── UserListView.swift<br>│   │   │   └── UserDetailView.swift<br>│   │   └── ViewModels/<br>│   │       └── UserViewModel.swift<br>│   ├── Post/<br>│   │   ├── Models/<br>│   │   │   └── Post.swift<br>│   │   ├── Views/<br>│   │   │   ├── PostListView.swift<br>│   │   │   └── PostDetailView.swift<br>│   │   └── ViewModels/<br>│   │       └── PostViewModel.swift<br>│   └── Comment/<br>│       ├── Models/<br>│       │   └── Comment.swift<br>│       ├── Views/<br>│       │   ├── CommentListView.swift<br>│       │   └── CommentDetailView.swift<br>│       └── ViewModels/<br>│           └── CommentViewModel.swift<br>├── Services/<br>│   ├── NetworkService.swift<br>│   └── DatabaseService.swift<br>└── Resources/<br>    ├── Assets.xcassets</pre><h3>Large Project with Features</h3><p><strong>Folder Structure:</strong></p><pre>MyApp/<br>├── MyAppApp.swift<br>├── Features/<br>│   ├── User/<br>│   │   ├── Models/<br>│   │   │   ├── User.swift<br>│   │   │   └── UserDTO.swift<br>│   │   ├── Views/<br>│   │   │   ├── UserListView.swift<br>│   │   │   └── UserDetailView.swift<br>│   │   ├── ViewModels/<br>│   │   │   └── UserViewModel.swift<br>│   │   └── Mappers/<br>│   │       └── UserMapper.swift<br>│   ├── Post/<br>│   │   ├── Models/<br>│   │   │   ├── Post.swift<br>│   │   │   └── PostDTO.swift<br>│   │   ├── Views/<br>│   │   │   ├── PostListView.swift<br>│   │   │   └── PostDetailView.swift<br>│   │   ├── ViewModels/<br>│   │   │   └── PostViewModel.swift<br>│   │   └── Mappers/<br>│   │       └── PostMapper.swift<br>│   ├── Comment/<br>│   │   ├── Models/<br>│   │   │   ├── Comment.swift<br>│   │   │   └── CommentDTO.swift<br>│   │   ├── Views/<br>│   │   │   ├── CommentListView.swift<br>│   │   │   └── CommentDetailView.swift<br>│   │   ├── ViewModels/<br>│   │   │   └── CommentViewModel.swift<br>│   │   └── Mappers/<br>│   │       └── CommentMapper.swift<br>│   └── Auth/<br>│       ├── Models/<br>│       │   └── AuthUser.swift<br>│       ├── Views/<br>│       │   ├── LoginView.swift<br>│       │   └── SignupView.swift<br>│       └── ViewModels/<br>│           └── AuthViewModel.swift<br>├── Services/<br>│   ├── Network/<br>│   │   ├── APIClient.swift<br>│   │   └── Endpoints.swift<br>│   ├── Database/<br>│   │   ├── CoreDataStack.swift<br>│   │   └── DatabaseManager.swift<br>│   └── AuthService.swift<br>├── Coordinators/<br>│   ├── AppCoordinator.swift<br>│   └── AuthCoordinator.swift<br>├── Utilities/<br>│   ├── Extensions/<br>│   │   ├── String+Extensions.swift<br>│   │   └── Date+Extensions.swift<br>│   ├── Helpers/<br>│   │   ├── ImageLoader.swift<br>│   │   └── JSONParser.swift<br>│   └── Constants.swift<br>└── Resources/<br>    ├── Assets.xcassets<br>   </pre><p><strong>File Names by Features:</strong></p><p><strong>Features/User</strong>:</p><ul><li>Models: User.swift, UserDTO.swift</li><li>Views: UserListView.swift, UserDetailView.swift</li><li>ViewModels: UserViewModel.swift</li><li>Mappers: UserMapper.swift</li></ul><p><strong>Features/Post</strong>:</p><ul><li>Models: Post.swift, PostDTO.swift</li><li>Views: PostListView.swift, PostDetailView.swift</li><li>ViewModels: PostViewModel.swift</li><li>Mappers: PostMapper.swift</li></ul><p><strong>Features/Comment</strong>:</p><ul><li>Models: Comment.swift, CommentDTO.swift</li><li>Views: CommentListView.swift, CommentDetailView.swift</li><li>ViewModels: CommentViewModel.swift</li><li>Mappers: CommentMapper.swift</li></ul><p><strong>Features/Auth</strong>:</p><ul><li>Models: AuthUser.swift</li><li>Views: LoginView.swift, SignupView.swift</li><li>ViewModels: AuthViewModel.swift</li><li><strong>Services</strong>: NetworkService.swift, DatabaseService.swift, APIClient.swift, Endpoints.swift, CoreDataStack.swift, DatabaseManager.swift, AuthService.swift</li><li><strong>Coordinators</strong>: AppCoordinator.swift, AuthCoordinator.swift</li><li><strong>Utilities</strong>: String+Extensions.swift, Date+Extensions.swift, ImageLoader.swift, JSONParser.swift, Constants.swift</li><li><strong>Resources</strong>: Assets.xcassets, LaunchScreen.storyboard</li></ul><p>This structure helps keep the project organized and maintainable, especially in larger teams or projects with many features.</p><h3>Separate Folders for Views and ViewModels</h3><p><strong>Pros:</strong></p><ol><li><strong>Clear Separation of Concerns</strong>: Easier to distinguish between UI and presentation logic.</li><li><strong>Scalability</strong>: Better organization as the project grows.</li><li><strong>Team Collaboration</strong>: Easier for different team members to work on UI and logic separately.</li></ol><p><strong>Cons:</strong></p><ol><li><strong>Navigation Overhead</strong>: Requires more navigation between folders, which can be cumbersome for small projects.</li><li><strong>Redundancy</strong>: Can feel redundant for simple views and view models.</li></ol><h3>Combined Folders for Views and ViewModels</h3><p><strong>Pros:</strong></p><ol><li><strong>Simplified Structure</strong>: Easier to navigate, especially in smaller projects.</li><li><strong>Contextual Grouping</strong>: View and ViewModel are side by side, making it easy to see the relationship between them.</li></ol><p><strong>Cons:</strong></p><ol><li><strong>Potential Clutter</strong>: As the project grows, these folders can become cluttered.</li><li><strong>Separation of Concerns</strong>: Less clear separation between UI and logic, which can lead to a less modular codebase.</li></ol><h3>Recommendations</h3><ul><li><strong>Small Projects</strong>: Combining Views and ViewModels within the same folder can keep things simple and easy to manage.</li><li><strong>Medium to Large Projects</strong>: Separate folders for Views and ViewModels will help maintain clarity and organization as the project scales.</li></ul><p><em>rogeriocpires@2024</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc86845eead8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>