<?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 Mihir Vikas Solanki on Medium]]></title>
        <description><![CDATA[Stories by Mihir Vikas Solanki on Medium]]></description>
        <link>https://medium.com/@mihir.solanki?source=rss-8707940abb56------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HaUj00mJBT77gHet</url>
            <title>Stories by Mihir Vikas Solanki on Medium</title>
            <link>https://medium.com/@mihir.solanki?source=rss-8707940abb56------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 07:57:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mihir.solanki/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[Delegation Pattern in Swift with Example]]></title>
            <link>https://medium.com/@mihir.solanki/delegation-pattern-in-swift-with-example-f77a60e9580b?source=rss-8707940abb56------2</link>
            <guid isPermaLink="false">https://medium.com/p/f77a60e9580b</guid>
            <category><![CDATA[delegate]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[protocol]]></category>
            <category><![CDATA[delegation]]></category>
            <dc:creator><![CDATA[Mihir Vikas Solanki]]></dc:creator>
            <pubDate>Sun, 25 Sep 2022 18:17:29 GMT</pubDate>
            <atom:updated>2022-09-26T10:59:42.997Z</atom:updated>
            <content:encoded><![CDATA[<h4>Easy way to understand and implement Delegation Pattern in swift.</h4><p>In This article we will learn about delegation pattern in swift and how to implement in the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*IARVOq_fmqXlH-b2Oy47pQ.jpeg" /></figure><p><strong>What is Protocol?</strong></p><blockquote><strong><em>According to </em></strong><a href="https://docs.swift.org/swift-book/LanguageGuide/Protocols.html"><strong><em>Apple Documentation</em></strong></a><strong><em>-</em></strong></blockquote><blockquote><em>A </em>protocol<em> defines a </em><strong><em>blueprint of methods</em></strong><em>, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be </em>adopted<em> by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to </em>conform<em> to that protocol.</em></blockquote><p>The protocol you have seen so many times in swift while developing the application.</p><p>Example:- <strong>UITableViewDelegate</strong> &amp; <strong>UITableViewDataSource</strong>. Both protocols having their methods required and optional.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m7HjOXisZu9BVgDXV8wuBg.png" /><figcaption>UITableViewDataSource</figcaption></figure><p>Let’s Implement the Delegation Pattern:</p><p>Example: Suppose you want to some perform an action of the button inside the UITableViewCell.</p><p>Let’s Create a Protocol</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40cc7c939b5100988d5da55cec0ab899/href">https://medium.com/media/40cc7c939b5100988d5da55cec0ab899/href</a></iframe><blockquote>I have created one protocol with the name GotoContentDetails and I am using here AnyObject because if you want to make it weak then you have to use it otherwise you can ignore it.</blockquote><p>Applying in the class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfbbf38d1849766e7c7f76e4990d3e8b/href">https://medium.com/media/bfbbf38d1849766e7c7f76e4990d3e8b/href</a></iframe><p>Call the delegate in goToContent action Button:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afa1d2d36626951407f37644fc16b9d6/href">https://medium.com/media/afa1d2d36626951407f37644fc16b9d6/href</a></iframe><p>Now Declare the Protocol in Main View Controller:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bfc2390366fae2f2eeaa507ab520430/href">https://medium.com/media/3bfc2390366fae2f2eeaa507ab520430/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60def58d649436fc03a18f57af213575/href">https://medium.com/media/60def58d649436fc03a18f57af213575/href</a></iframe><h3>How to make the Optional Protocol method?</h3><p>By adding @objc with your protocol and with <strong>@objc optional method</strong> you can make it. 👍🏽</p><p><strong>Protocol requirements with default implementations provided by extensions</strong> are distinct from optional protocol requirements. Although conforming types don’t have to provide their own implementation of either, requirements with default implementations can be called without optional chaining.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9909cc1368ee4b962d57ba45ca8fe9e7/href">https://medium.com/media/9909cc1368ee4b962d57ba45ca8fe9e7/href</a></iframe><blockquote>Conclusion</blockquote><blockquote>In this article, we have seen what is protocol. How to create it and how to work with the delegation pattern. After that also you got understanding with optional and required protocol methods. By default, methods will be required.</blockquote><blockquote><em>Do let me know if I missed something. Or if you can think of any more use cases.<br>Thanks for your time. :)</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f77a60e9580b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency Injection in Swift]]></title>
            <link>https://medium.com/@mihir.solanki/dependency-injection-in-swift-c0a21d9b7650?source=rss-8707940abb56------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a21d9b7650</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Mihir Vikas Solanki]]></dc:creator>
            <pubDate>Sat, 27 Aug 2022 22:29:15 GMT</pubDate>
            <atom:updated>2022-08-28T08:01:39.972Z</atom:updated>
            <content:encoded><![CDATA[<h4>Easy Way To Understand and Implement Dependency Injection in Swift</h4><p>In this article we’ll learn how to use Dependency injection in swift in a simple way without any external api.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2znGy2wPe8gXWD7Qf9SmhQ.png" /></figure><p><strong>What’s dependency injection?</strong></p><blockquote><em>In software development, </em><strong><em>dependency injection</em></strong><em> is a technique in which an </em><a href="https://en.wikipedia.org/wiki/Object_(computer_science)"><em>object</em></a><em> receives other objects that it depends on.</em></blockquote><blockquote>But this definition isn’t helpful. let’s make practical example.</blockquote><blockquote>We want to create an application class which depends on a <strong>design</strong>, <strong>api</strong>, <strong>appContent</strong>, <strong>qc</strong> and <strong>approval.</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3c1667a14ca6174b744a7cb791ff8df/href">https://medium.com/media/b3c1667a14ca6174b744a7cb791ff8df/href</a></iframe><p><strong>Cons of the App class:</strong></p><p>Since our <strong>app</strong> components are initialized within the <strong>app</strong> <strong>class</strong>, we have several disadvantages like:</p><ul><li>Strong coupling between a class and its dependencies</li><li>Poor maintainability</li><li>If the new developer come in the company they don’t know the hidden dependencies in the <strong>class App.</strong></li></ul><p><strong>Solution:</strong></p><blockquote>I’ll propose two simple ways to apply dependency injection to our <strong>App Class</strong></blockquote><h3>Property injection:</h3><blockquote>With this solution we can provide dependencies using setters.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb19781b219d6cd9c561da311866795b/href">https://medium.com/media/bb19781b219d6cd9c561da311866795b/href</a></iframe><p>In order to apply dependency in a <strong>App</strong> <strong>class</strong> we just have to call the setters.</p><p>This provides more flexibility since we can change our dependencies in any moment and provides more readability.</p><p>we expose the class encapsulation and make the class error prone since we’re not providing dependencies when the class is initialized.</p><h3>Initializer Injection:</h3><p>I personally prefer to pass dependencies during the initialization phase of an object because this has several key benefits. The most important benefit is that dependencies passed in during initialization can be made immutable. This is very easy to do in Swift by declaring the properties for the dependencies as constants.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba0ee0b4a1692d908b324907e666585f/href">https://medium.com/media/ba0ee0b4a1692d908b324907e666585f/href</a></iframe><p>In this way we just need to provide our design, api, appContent, qc and approval during the <strong>App</strong> initialization.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2791d6174557fa3d693d767a86ae0cf/href">https://medium.com/media/d2791d6174557fa3d693d767a86ae0cf/href</a></iframe><p>This provides a correct <strong>encapsulation</strong> and grants that the dependencies are always in a valid state.</p><p>On the other hand, it’s a less flexible solution since we cannot change the components once the class is initialized.</p><blockquote>Do let me know if I missed something. Or if you can think of any more use cases. <br>Thanks for your time. :)</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a21d9b7650" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>