<?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 Kapil Shivhare on Medium]]></title>
        <description><![CDATA[Stories by Kapil Shivhare on Medium]]></description>
        <link>https://medium.com/@codable-kapil?source=rss-235dcf022cb2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aVjrKfSyMBNYiTOHjs9_cw.jpeg</url>
            <title>Stories by Kapil Shivhare on Medium</title>
            <link>https://medium.com/@codable-kapil?source=rss-235dcf022cb2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 03:22:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codable-kapil/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[Mastering REST API Integration in Swift: A Step-by-Step Guide]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@codable-kapil/interacting-with-rest-apis-using-swift-0fd8356b84a6?source=rss-235dcf022cb2------2"><img src="https://cdn-images-1.medium.com/max/2600/0*MUZFsv_ySvrBcgJo" width="5749"></a></p><p class="medium-feed-snippet">In modern iOS development, working with REST APIs is a common task. Whether you&#x2019;re fetching data from a remote server or sending updates&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@codable-kapil/interacting-with-rest-apis-using-swift-0fd8356b84a6?source=rss-235dcf022cb2------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@codable-kapil/interacting-with-rest-apis-using-swift-0fd8356b84a6?source=rss-235dcf022cb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/0fd8356b84a6</guid>
            <category><![CDATA[asynchronous-programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[rest-api-integration]]></category>
            <category><![CDATA[async-await-in-swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Kapil Shivhare]]></dc:creator>
            <pubDate>Fri, 24 Jan 2025 06:41:16 GMT</pubDate>
            <atom:updated>2025-01-24T06:49:56.714Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[SwiftData: Simplified Data Management for iOS Apps]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@codable-kapil/swiftdata-simplified-data-management-for-ios-apps-ee85cb2e49b7?source=rss-235dcf022cb2------2"><img src="https://cdn-images-1.medium.com/max/600/1*-at5lfY2lnPRgnw_pzvA0g.png" width="600"></a></p><p class="medium-feed-snippet">With the release of SwiftData in iOS 16, Apple has introduced a new framework designed to streamline data management in iOS apps. Built on&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@codable-kapil/swiftdata-simplified-data-management-for-ios-apps-ee85cb2e49b7?source=rss-235dcf022cb2------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@codable-kapil/swiftdata-simplified-data-management-for-ios-apps-ee85cb2e49b7?source=rss-235dcf022cb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee85cb2e49b7</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift-concurrency]]></category>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[data-management]]></category>
            <category><![CDATA[swiftdata]]></category>
            <dc:creator><![CDATA[Kapil Shivhare]]></dc:creator>
            <pubDate>Thu, 09 Jan 2025 06:42:56 GMT</pubDate>
            <atom:updated>2025-01-09T06:42:56.715Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[What’s your Leadership Style?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@codable-kapil/whats-your-leadership-style-5c98788f8ef8?source=rss-235dcf022cb2------2"><img src="https://cdn-images-1.medium.com/max/2600/0*-XsYNGFCOfTkPsXU" width="3840"></a></p><p class="medium-feed-snippet">Leadership is a fascinating topic, and it&#x2019;s more than just being in charge; it&#x2019;s about inspiring others, guiding teams, and making&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@codable-kapil/whats-your-leadership-style-5c98788f8ef8?source=rss-235dcf022cb2------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@codable-kapil/whats-your-leadership-style-5c98788f8ef8?source=rss-235dcf022cb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c98788f8ef8</guid>
            <category><![CDATA[project-management]]></category>
            <category><![CDATA[leadership-styles]]></category>
            <category><![CDATA[people-management]]></category>
            <category><![CDATA[engineering-management]]></category>
            <category><![CDATA[team-building]]></category>
            <dc:creator><![CDATA[Kapil Shivhare]]></dc:creator>
            <pubDate>Sat, 26 Oct 2024 23:59:50 GMT</pubDate>
            <atom:updated>2024-10-29T05:04:34.939Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Enhancing Developer Experience for Engineering Teams]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@codable-kapil/enhancing-developer-experience-for-engineering-teams-d0ae1658952f?source=rss-235dcf022cb2------2"><img src="https://cdn-images-1.medium.com/max/2600/0*MsI3c350vB9JAEEP" width="3882"></a></p><p class="medium-feed-snippet">In today&#x2019;s fast-paced tech landscape, ensuring a positive developer experience is crucial for the success and productivity of iOS&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@codable-kapil/enhancing-developer-experience-for-engineering-teams-d0ae1658952f?source=rss-235dcf022cb2------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@codable-kapil/enhancing-developer-experience-for-engineering-teams-d0ae1658952f?source=rss-235dcf022cb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0ae1658952f</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[developer-experience]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Kapil Shivhare]]></dc:creator>
            <pubDate>Mon, 21 Oct 2024 23:56:00 GMT</pubDate>
            <atom:updated>2024-10-21T23:56:00.325Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Different Ways of Getting Data from an API Endpoint in Swift]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@codable-kapil/different-ways-of-getting-data-from-an-api-endpoint-in-swift-8b1d5933c9dd?source=rss-235dcf022cb2------2"><img src="https://cdn-images-1.medium.com/max/2600/1*k72wFD0kmtSs3XA1cpStpA.jpeg" width="3840"></a></p><p class="medium-feed-snippet">If you&#x2019;re venturing into the realm of iOS app development, one of the most essential skills you&#x2019;ll need is fetching data from an API&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@codable-kapil/different-ways-of-getting-data-from-an-api-endpoint-in-swift-8b1d5933c9dd?source=rss-235dcf022cb2------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@codable-kapil/different-ways-of-getting-data-from-an-api-endpoint-in-swift-8b1d5933c9dd?source=rss-235dcf022cb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b1d5933c9dd</guid>
            <category><![CDATA[api-endpoint]]></category>
            <category><![CDATA[combine]]></category>
            <category><![CDATA[async-await-in-swift]]></category>
            <category><![CDATA[iosnetworking]]></category>
            <category><![CDATA[completion-handlers]]></category>
            <dc:creator><![CDATA[Kapil Shivhare]]></dc:creator>
            <pubDate>Wed, 02 Oct 2024 07:17:06 GMT</pubDate>
            <atom:updated>2024-10-02T07:17:06.135Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Implementing MVVM with Swift: Harnessing Protocol-Oriented Programming and Dependency Injection for…]]></title>
            <link>https://medium.com/@codable-kapil/implementing-mvvm-with-swift-harnessing-protocol-oriented-programming-and-dependency-injection-ba38eef0c674?source=rss-235dcf022cb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba38eef0c674</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mvvm]]></category>
            <dc:creator><![CDATA[Kapil Shivhare]]></dc:creator>
            <pubDate>Thu, 19 Sep 2024 05:05:10 GMT</pubDate>
            <atom:updated>2024-09-19T05:05:10.885Z</atom:updated>
            <content:encoded><![CDATA[<h3>Implementing MVVM with Swift: Harnessing Protocol-Oriented Programming and Dependency Injection for Effortless Unit Testing</h3><p>When diving into iOS development, you’ve likely encountered the Model-View-ViewModel (MVVM) design pattern. It’s a favorite among developers for a good reason — its separation of concerns promotes clean and maintainable code. Pairing MVVM with Swift’s protocol-oriented programming and dependency injection can elevate your coding experience, especially when it comes to unit testing. In this blog, we’ll explore how to implement MVVM in your Swift projects while keeping unit testing straightforward and enjoyable. Let’s get started!</p><h3>What is MVVM?</h3><p>Before we dive into implementation, let’s quickly recap what MVVM is all about. At its core, MVVM separates your application into three main components:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*aiF1I_h49DGsHw0N-2M0KA.png" /><figcaption>MVVM flow</figcaption></figure><ol><li><strong>Model</strong>: This is your data layer, where the app’s data and business logic reside.</li><li><strong>View</strong>: This is the UI layer. In iOS, it consists of your views (like UIViewController and UIView).</li><li><strong>ViewModel</strong>: This acts as a bridge between the Model and the View. It prepares data for the View and responds to user actions.</li></ol><p>The beauty of MVVM lies in its ability to allow for easier unit testing and a more structured codebase, making it a preferred choice for many developers.</p><h3>Why Protocol-Oriented Programming?</h3><p>Swift is built with protocol-oriented programming in mind. This means that instead of relying solely on class inheritance, you can define protocols that outline what methods or properties a conforming type should implement. This promotes flexibility and reusability in your code.</p><p>Using protocols in MVVM not only makes your code more organized but also significantly enhances your unit testing capabilities. You can create mock objects that conform to your protocols, making it easy to isolate your ViewModel during tests.</p><h3>What is Dependency Injection?</h3><p>Dependency Injection (DI) is a design pattern used to implement IoC (Inversion of Control), allowing for better separation of concerns and making your code more testable. In essence, it means providing a class with its dependencies from the outside rather than creating them internally.</p><p>This is especially useful in MVVM architecture because it allows your ViewModel to focus solely on its responsibilities without being tightly coupled to the specific implementations of its dependencies (like network services).</p><h3>Setting Up Your Project</h3><p>Let’s set up a simple project that displays a list of items fetched from a network. Here’s how you can implement MVVM using protocol-oriented programming and dependency injection.</p><h4>1. Create Your Model</h4><p>Start by defining your Model. This will represent the data structure of your application</p><pre>struct Item: Codable {<br>    let id: Int<br>    let name: String<br>}</pre><h4>2. Define a Protocol for Your ViewModel</h4><p>Next, create a protocol that outlines the functionality your ViewModel should provide. This includes properties for your View to bind to and methods for user interactions.</p><pre>protocol ItemViewModelProtocol {<br>    var items: [Item] { get }<br>    func fetchItems(completion: @escaping () -&gt; Void)<br>}</pre><h4>3. Define a Network Service Protocol</h4><p>We need a way to fetch data from a network source. By defining a protocol for our network service, we can easily mock it for unit testing.</p><pre>protocol ItemServiceProtocol {<br>    func fetchItems(completion: @escaping (Result&lt;[Item], Error&gt;) -&gt; Void)<br>}</pre><h4>4. Implement the Network Service</h4><p>Now, create a concrete implementation of the service. This will handle the actual network request to fetch items.</p><pre>import Foundation<br><br>class ItemService: ItemServiceProtocol {<br>    func fetchItems(completion: @escaping (Result&lt;[Item], Error&gt;) -&gt; Void) {<br>        let urlString = &quot;https://example.com/api/items&quot;<br>        guard let url = URL(string: urlString) else {<br>            completion(.failure(NSError(domain: &quot;Invalid URL&quot;, code: 0)))<br>            return<br>        }<br><br>        let task = URLSession.shared.dataTask(with: url) { data, response, error in<br>            if let error = error {<br>                completion(.failure(error))<br>                return<br>            }<br><br>            guard let data = data else {<br>                completion(.failure(NSError(domain: &quot;No data&quot;, code: 0)))<br>                return<br>            }<br><br>            do {<br>                let items = try JSONDecoder().decode([Item].self, from: data)<br>                completion(.success(items))<br>            } catch {<br>                completion(.failure(error))<br>            }<br>        }<br><br>        task.resume()<br>    }<br>}</pre><h4>5. Implement Your ViewModel with Dependency Injection</h4><p>Now, create a ViewModel that conforms to the ItemViewModelProtocol. Use dependency injection to pass the ItemServiceProtocol instance to the ViewModel.</p><pre>import Foundation<br><br>class ItemViewModel: ItemViewModelProtocol {<br>    private(set) var items: [Item] = []<br>    private let service: ItemServiceProtocol<br><br>    // Dependency Injection through the initializer<br>    init(service: ItemServiceProtocol) {<br>        self.service = service<br>    }<br><br>    func fetchItems(completion: @escaping () -&gt; Void) {<br>        service.fetchItems { [weak self] result in<br>            switch result {<br>            case .success(let items):<br>                self?.items = items<br>                completion()<br>            case .failure(let error):<br>                print(&quot;Error fetching items: \(error)&quot;)<br>                completion()<br>            }<br>        }<br>    }<br>}</pre><h4>6. Set Up Your View</h4><p>Your View will typically be a UIViewController. It will create an instance of the ViewModel using dependency injection and bind its UI elements to the ViewModel’s properties.</p><pre>import UIKit<br><br>class ItemViewController: UIViewController {<br>    var viewModel: ItemViewModelProtocol!<br>    private var tableView: UITableView!<br><br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        setupUI()<br>        viewModel.fetchItems { [weak self] in<br>            DispatchQueue.main.async {<br>                self?.tableView.reloadData()<br>            }<br>        }<br>    }<br><br>    private func setupUI() {<br>        title = &quot;Items&quot;<br>        tableView = UITableView(frame: view.bounds)<br>        tableView.dataSource = self<br>        view.addSubview(tableView)<br>    }<br>}<br><br>extension ItemViewController: UITableViewDataSource {<br>    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {<br>        return viewModel.items.count<br>    }<br><br>    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {<br>        let cell = tableView.dequeueReusableCell(withIdentifier: &quot;Cell&quot;) ?? UITableViewCell(style: .default, reuseIdentifier: &quot;Cell&quot;)<br>        let item = viewModel.items[indexPath.row]<br>        cell.textLabel?.text = item.name<br>        return cell<br>    }<br>}</pre><h3>Unit Testing Your ViewModel</h3><p>One of the standout features of using protocol-oriented programming with MVVM is the ease of unit testing. You can create a mock ViewModel to simulate data without having to rely on the real implementation.</p><h4>1. Create a Mock Service</h4><p>Here’s a quick mock version of your network service for testing:</p><pre>class MockItemService: ItemServiceProtocol {<br>    var shouldReturnError = false<br><br>    func fetchItems(completion: @escaping (Result&lt;[Item], Error&gt;) -&gt; Void) {<br>        if shouldReturnError {<br>            completion(.failure(NSError(domain: &quot;Test error&quot;, code: 1)))<br>        } else {<br>            let mockItems = [<br>                Item(id: 1, name: &quot;Mock Item 1&quot;),<br>                Item(id: 2, name: &quot;Mock Item 2&quot;)<br>            ]<br>            completion(.success(mockItems))<br>        }<br>    }<br>}</pre><h4>2. Write Your Tests</h4><p>Now you can write tests using the mock service:</p><pre>import XCTest<br><br>class ItemViewModelTests: XCTestCase {<br>    var viewModel: ItemViewModelProtocol!<br>    var service: MockItemService!<br><br>    override func setUp() {<br>        super.setUp()<br>        service = MockItemService()<br>        viewModel = ItemViewModel(service: service)<br>    }<br><br>    func testFetchItemsSuccess() {<br>        service.shouldReturnError = false<br>        let expectation = XCTestExpectation(description: &quot;Fetch items&quot;)<br>        <br>        viewModel.fetchItems {<br>            XCTAssertEqual(self.viewModel.items.count, 2)<br>            XCTAssertEqual(self.viewModel.items[0].name, &quot;Mock Item 1&quot;)<br>            expectation.fulfill()<br>        }<br>        <br>        wait(for: [expectation], timeout: 1.0)<br>    }<br>    <br>    func testFetchItemsFailure() {<br>        service.shouldReturnError = true<br>        let expectation = XCTestExpectation(description: &quot;Fetch items with error&quot;)<br>        <br>        viewModel.fetchItems {<br>            XCTAssertEqual(self.viewModel.items.count, 0)<br>            expectation.fulfill()<br>        }<br>        <br>        wait(for: [expectation], timeout: 1.0)<br>    }<br>}</pre><h3>Benefits of This Approach</h3><ol><li><strong>Separation of Concerns</strong>: Your ViewModel only knows about your Model, not how the data is displayed or fetched. This makes it easy to update the View without touching the logic.</li><li><strong>Testability</strong>: With protocols and dependency injection, you can easily swap out your real ViewModel for a mock version, simplifying unit tests significantly.</li><li><strong>Reusability</strong>: Protocols allow you to create reusable components. Different ViewModels can conform to the same protocol, ensuring consistency across your app.</li><li><strong>Simplified Dependency Management</strong>: By injecting dependencies, you reduce tight coupling between components, making it easier to manage changes and test in isolation.</li><li><strong>Ease of Network Calls</strong>: By abstracting network calls behind protocols, you can easily swap out or mock services without affecting your ViewModel logic.</li></ol><h3>Putting It All Together</h3><p>Now that we have a complete implementation of MVVM using protocol-oriented programming and dependency injection, let’s summarize what we’ve done:</p><ul><li><strong>Created a Model</strong>: Defined a simple Item model that conforms to Codable.</li><li><strong>Defined Protocols</strong>: Created protocols for both the ViewModel and the network service to allow for flexibility and testability.</li><li><strong>Implemented ViewModel and Service</strong>: Built a concrete ItemViewModel that fetches data from an ItemService, injected via dependency injection.</li><li><strong>Set Up the View</strong>: Created a simple ItemViewController that displays the items in a table view.</li><li><strong>Tested the ViewModel</strong>: Implemented unit tests to ensure our ViewModel behaves correctly under different conditions using a mock service.</li></ul><h3>Conclusion</h3><p>Implementing MVVM with Swift using protocol-oriented programming and dependency injection isn’t just about following a pattern; it’s about creating a scalable, maintainable, and testable codebase. This approach empowers you to build applications that are robust, easy to understand, and manage.</p><p>As you embark on your iOS development journey, consider leveraging MVVM, protocols, and dependency injection to enhance your workflow. Your future self — and your codebase — will thank you for it!</p><p>Feel free to share your thoughts and experiences with MVVM and protocol-oriented programming in the comments below! Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba38eef0c674" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>