<?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 Hasan Acar on Medium]]></title>
        <description><![CDATA[Stories by Hasan Acar on Medium]]></description>
        <link>https://medium.com/@hsnxcr?source=rss-39fa2948b849------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hj7cqmlJUjhzF0TQWoOQQA.jpeg</url>
            <title>Stories by Hasan Acar on Medium</title>
            <link>https://medium.com/@hsnxcr?source=rss-39fa2948b849------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:02:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hsnxcr/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[UICollectionView Diffable Datasource Wrapper with Loading Indicator and Multiple Section Layouts…]]></title>
            <link>https://hsnxcr.medium.com/uicollectionviewdiffabledatasource-wrapper-for-handling-multiple-section-layout-and-more-1c387b01d179?source=rss-39fa2948b849------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c387b01d179</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[hunter-x-hunter]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[uicollectionview]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Hasan Acar]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 18:10:41 GMT</pubDate>
            <atom:updated>2024-05-07T12:46:32.548Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WGVeWaTMqPAeX2Xgcw5ug.jpeg" /></figure><h3>UICollectionView Diffable Datasource Wrapper with Loading Indicator and Multiple Section Layouts Handling</h3><p>With <strong>SwiftUI</strong>, Apple created a really simple way to build user interfaces using declarative approach. <strong>Apple </strong>also introduced new <strong>UIKit </strong>APIs with iOS 13 to simplify UIKit implementations. Even, potential of SwiftUI is greater than creating simple user interfaces; New UIKit APIs are also helping to create interfaces as declarative as possible and it still shows a promise, IMO.</p><p><em>Using </em><strong><em>UICollectionViewDiffableDatasource</em></strong><em>, </em>we easily manage the handling of datasource changes and defining multiple sections with different section layouts. Also, combining these features, we could add extra capabilities into our datasource wrapper.</p><p>I created this datasource wrapper to achieve to create collection views and its layouts with ease. Using enums, we can define sections and items for our collection view and only worry about providing cells and applying snapshots.</p><p>Let’s start to create following use case;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YoN61s5jQZzVmS2-UPlFDA.gif" /></figure><p>First define section and item enums that we want to use for this use case;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c460266ef52d6c60d79262b82bf09670/href">https://medium.com/media/c460266ef52d6c60d79262b82bf09670/href</a></iframe><p>Secondly, we define section layouts inside our section enum; so, our wrapper uses it when it needs to provide <em>NSCollectionLayoutSection</em>.</p><p><em>DiffableDatasource</em> redraws its content when orientation changes; So, we can add additional constraints in here to layout our UI properly. For example, following code will group its content with 2 columns on landscape mode.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48bac4866541a3a8c1f5512ce039cd01/href">https://medium.com/media/48bac4866541a3a8c1f5512ce039cd01/href</a></iframe><p>Thirdly, define the datasource to handle creations of cells and supplementary views.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c5b0857d2a52a7a375a5bdefe1b703e/href">https://medium.com/media/9c5b0857d2a52a7a375a5bdefe1b703e/href</a></iframe><p>Now, our datasource is ready to use with a little configuration on <em>viewDidLoad</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83efcb4ce04b29f4380f52c198bef990/href">https://medium.com/media/83efcb4ce04b29f4380f52c198bef990/href</a></iframe><p>Rest is handling the loading data and applying snapshots with those related data. Here is the final result;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dL6-tErD7qRsMKB9TOgSXQ.gif" /></figure><p>You can access above implementation from <a href="https://github.com/hsncr/Huncyclopedia"><strong>this repository</strong></a></p><h3>Takeaways</h3><p>Using <em>UICollectionViewDiffableDatasource </em>is straightforward. It can easily be wrapped to implement additional features on top of it and probably you will never need the <em>UITableViewDiffableDatasource </em>again.</p><p>Handling different section layout contents in <em>UICollectionViewDiffableDatasource </em>is one of the problems that you need to solve to make it reusable<em>.</em> I hope that this wrapper implementation can be a starting point for you to help solving it and to implement additional use cases you require.</p><p>Let me know if you have any feedbacks or comments.</p><p>Thanks for reading.</p><h3>Resources</h3><ul><li><a href="https://hsnxcr.medium.com/coordinator-pattern-using-apple-combine-framework-e2efd78bbe01">Coordinator Pattern using Apple Combine Framework</a></li><li><a href="https://hsnxcr.medium.com/storyboardloadable-a75c55763381">StoryboardLoadable</a></li><li><a href="https://hsnxcr.medium.com/prefixuntiloutput-and-custom-takeuntil-publisher-operators-in-apple-combine-framework-8c71ed7551ab">PrefixUntilOutput and Custom “TakeUntil” Publisher Operators in Apple Combine Framework</a></li><li><a href="https://developer.apple.com/documentation/uikit/uicollectionviewdiffabledatasource">UICollectionViewDiffableDataSource | Apple Developer Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c387b01d179" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coordinator Pattern using Apple Combine Framework]]></title>
            <link>https://hsnxcr.medium.com/coordinator-pattern-using-apple-combine-framework-e2efd78bbe01?source=rss-39fa2948b849------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2efd78bbe01</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[coordinator-pattern]]></category>
            <category><![CDATA[combine]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[coordinator]]></category>
            <dc:creator><![CDATA[Hasan Acar]]></dc:creator>
            <pubDate>Wed, 03 Feb 2021 15:30:10 GMT</pubDate>
            <atom:updated>2021-03-01T20:48:52.403Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ne_QihZYknGlls7aiw-1Iw.jpeg" /></figure><p><strong>Coordinator Pattern</strong> is one of the ways to implement a navigation control flow on iOS applications. Coordinators make it easy to test and encapsulate the navigation logic; it also helps to create reusable components, to use them on horizontal(push) or vertical(present) flows. It is a great place to implement deep linking and to provide dependencies between flows.</p><p>However, you have to be careful to handle lifecycles of the coordinators in order to avoid memory leaks. Especially <strong>back button taps</strong>, <strong>swipe back</strong> and <strong>iOS 13 dismiss gesture events</strong> can create memory leaks if those events are not handled properly.</p><p>To handle lifecycles of the coordinators; you could bind it onto view controller by holding them inside view controllers, or carefully detect pop and dismiss events to release them from their parent coordinators.</p><p>Using reactive streams to bind coordinators together makes it easy to handle those events and react to them.</p><p>In this article, you will find a tab bar application that <a href="https://khanlou.com/2015/01/the-coordinator/"><strong>Coordinator Pattern</strong></a> with <a href="https://developer.apple.com/documentation/combine"><strong>Apple Combine Framework</strong></a><em> </em>is used to implement its navigation logic.</p><p>Let’s start with the <em>BaseCoordinator</em> definition;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc78a0b257db91e2a023b91e900a9a4b/href">https://medium.com/media/bc78a0b257db91e2a023b91e900a9a4b/href</a></iframe><p>Each <em>Coordinator</em> is bound to its source view controller which can be defined directly or wrapped inside a navigation controller on the source property. <em>BaseCoordinator</em> uses the router to perform navigation actions and holds child coordinators to release them from memory after receiving a single event which could be a response from the child coordinator or a system call that can be triggered by pop or dismiss events.</p><p>It has basic <em>push</em>, <em>present</em>, <em>setViewController</em> and <em>setRoot</em> methods to determine the type of the navigation action, to perform on the passed coordinator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e474925a9f076ff413f1420db8edd66/href">https://medium.com/media/4e474925a9f076ff413f1420db8edd66/href</a></iframe><p><em>Router</em> class implements system functions of the navigation controller such as push, present, pop and dismiss operations and calls closures, so coordinator can release its child coordinators. I wanted to hold release closures of child view controllers on tied custom <em>NavigationController</em> so I can freely pass around related <em>NavigationController</em> and create the <em>Router</em> on the spot. If parent navigation controller is passed into the child coordinator, then all of its operation will be performed on it. If we want to present another view controller on top of the presented view controller, then we have to pass freshly created <em>NavigationController</em> into the child coordinator to present and use it inside our new flows.</p><p>Lets continue with the implementation of following flow;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*czzT4xoRE03St-8w8VKeJg.png" /><figcaption>Navigation Flow</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0585d7ad8e5d45573f61fd132e778fb1/href">https://medium.com/media/0585d7ad8e5d45573f61fd132e778fb1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*AF8OD_meR_8oIEOwLBO0tA.gif" /><figcaption>AppCoordinator in action</figcaption></figure><p>Initially, <em>AppCoordinator</em> is called to start the <em>SplashCoordinator</em> using <em>setRoot</em> method. After 1 second <em>SplashCoordinator</em> sends an event back to the <em>AppCoordinator,</em> to continue the execution and to start the <em>TabCoordinator</em> using the same method. In the meantime <em>SplashCoordinator</em> is released inside the <em>coordinate(to:)</em> function due to <em>receivedOutput </em>event.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f09fd6cbb6f63a11b0e9ae6d7ec3cdad/href">https://medium.com/media/f09fd6cbb6f63a11b0e9ae6d7ec3cdad/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*-n3HwBahpVbPmVgZ_qLeMg.gif" /><figcaption>ComposeCoordinator in action</figcaption></figure><p><em>LizardCoordinators</em> don’t publish any events back to the TabCoordinator by returning custom <em>Never</em> publisher, which is <em>Empty(completeImmediately: false)</em> publisher under the hood. However it observes the button event to present a <em>ComposeCoordinator</em> on the vertical flow. By passing freshly created <em>NavigationController</em> on the <em>ComposeCoordinator</em>, router uses that navigation controller as a source view controller to present it.</p><p>It is also used to create new <em>Router</em> inside the <em>ComposeCoordinator</em> which then will present another <em>ComposeCoordinator </em>recursively on command.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8401f6ef0950ce1a49c786970903a13/href">https://medium.com/media/e8401f6ef0950ce1a49c786970903a13/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*zRkSZJAEQtFBR2Zek3nNrQ.gif" /><figcaption>WakingUpCoordinator in action</figcaption></figure><p><em>WakingUpCoordinator </em>observes the <em>openUrlSubject </em>to present <a href="https://wakingup.com/"><strong>Waking Up</strong></a> application website on a <em>SafariViewController</em> via <em>SafariCoordinator</em>.</p><p>It can also push and observe output of the <em>SettingsCoordinator</em>.</p><p>BTW if you can’t afford it, you can request a free account access from <strong>Waking Up</strong> application via <a href="https://app.wakingup.com/request-free-account">this link</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cac30bde89922021d044bfb1553a83b/href">https://medium.com/media/7cac30bde89922021d044bfb1553a83b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*bcFhluDL9B8-W6Wlrmh_kA.gif" /><figcaption>Logout in action</figcaption></figure><p><em>SettingsCoordinator</em> is pushed on the horizontal flow inside the <em>WakingUpCoordinator </em>and <em>it </em>returns a <em>logoutAction </em>event through the <em>WakingUpCoordinator </em>into <em>AppCoordinator,</em> to perform logout and start application flow again with the <em>SplashCoordinator</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*qCGx5FSBb7z7KFM_WnMa1A.gif" /><figcaption>Multiple push on SettingsCoordinator and Logout in action</figcaption></figure><p>We could just push our <em>SettingsCoordinator</em> on the horizontal flow indefinitely and pass our logout action back to the navigation stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*J4RLO1uCg1vjxAv8xZ9gtg.gif" /><figcaption>Present ComposeCoordinator inside SettingsCoordinator</figcaption></figure><p>We could easily use <em>ComposeCoordinator</em> to present it inside the <em>SettingsCoordinator </em>in the same way on our<em> LizardCoordinator</em>.</p><p>You can access above implementation from <a href="https://github.com/hsncr/ZinZinZin"><strong>this repository</strong></a></p><h3>Takeaways</h3><p>Extracting navigation logic outside of the view controllers helps to solve the <em>Massive View Controller</em> problem on iOS development. Coordinators are also great place to implement dependency injection besides the navigation logic. We could easily provide dependencies inside them and pass necessary parameters through the navigation flows.</p><p>I tried to implement the <em>BaseCoordinator</em> to handle most of the navigation commands. I wanted to easily push and present coordinators without getting involved in dismissing action and only focusing on the events that our business logic concerns.</p><p>I hope that this article could be a starting point for you to implement the coordinator pattern using Apple Combine framework. You could add a couple of changes and have fully functional and testable coordinators on your project.</p><p>Let me know if you have any feedbacks or comments.</p><p>Thanks for reading.</p><h4>Resources</h4><ul><li><a href="https://hsnxcr.medium.com/storyboardloadable-a75c55763381">StoryboardLoadable</a></li><li><a href="https://hsnxcr.medium.com/prefixuntiloutput-and-custom-takeuntil-publisher-operators-in-apple-combine-framework-8c71ed7551ab">PrefixUntilOutput and Custom “TakeUntil” Publisher Operators in Apple Combine Framework</a></li></ul><p><a href="https://khanlou.com/2015/01/the-coordinator/">https://khanlou.com/2015/01/the-coordinator/</a></p><ul><li><a href="https://uptech.team/blog/mvvm-coordinators-and-rxswift">Taming Great Complexity: MVVM, Coordinators and RxSwift</a></li><li><a href="https://benoitpasquier.com/coordinator-pattern-navigation-back-button-swift/">Coordinator &amp; MVVM - Clean Navigation and Back Button in Swift</a></li></ul><p><a href="https://hackernoon.com/coordinators-routers-and-back-buttons-c58b021b32a">https://hackernoon.com/coordinators-routers-and-back-buttons-c58b021b32a</a></p><p><a href="https://benoitpasquier.com/integrate-coordinator-pattern-in-rxswift/">https://benoitpasquier.com/integrate-coordinator-pattern-in-rxswift/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2efd78bbe01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PrefixUntilOutput and Custom “TakeUntil” Publisher Operators in Apple Combine Framework]]></title>
            <link>https://hsnxcr.medium.com/prefixuntiloutput-and-custom-takeuntil-publisher-operators-in-apple-combine-framework-8c71ed7551ab?source=rss-39fa2948b849------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c71ed7551ab</guid>
            <category><![CDATA[rxswift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[apple-combine]]></category>
            <category><![CDATA[combine]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Hasan Acar]]></dc:creator>
            <pubDate>Tue, 26 Jan 2021 11:19:33 GMT</pubDate>
            <atom:updated>2021-03-01T20:01:54.287Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C6s88kJzzL9rc9xYizf8Kw.jpeg" /></figure><h3>PrefixUntilOutput and Custom “TakeUntil” Publisher Operators on Apple Combine Framework</h3><p>Combine framework was introduced at WWDC 2019 as a new way of reactive programming on Apple platforms. It has native support on all Apple platforms that runs iOS 13+, iPadOS 13+, macOS 10.15+, watchOS 6+ or tvOS 13+; however, it has a couple of fundamental problems on beta and early iOS 13 versions as Matt Gallagher mentioned in his great <a href="https://www.cocoawithlove.com/blog/twenty-two-short-tests-of-combine-part-1.html">articles</a>. Even they are mostly fixed on later versions, you could still encounter unexpected behaviors on iOS 14 and I will try to cover one of them.</p><p>In this article, I will explain the built-in <em>PrefixUntilOutput AKA prefix(untilOutputFrom:)</em> publisher operator. Also I will create a custom publisher operator that runs its completion when the tied publisher terminates or emits a value, just as RxJava “<strong>TakeUntil</strong>” implementation.</p><h4><strong>A little Concept</strong></h4><p>Lets look at Apple’s definition of the Combine;</p><blockquote>Combine is a unified declarative framework for processing values over time.</blockquote><p>In the Combine or any other reactive framework, you expect your events as a stream and hopefully you get a completion as an error or a successful termination. Combine uses <em>Publisher </em>and<em> Subscriber</em> concepts based on <a href="https://www.reactive-streams.org/"><strong><em>ReactiveStreams</em></strong></a> to provide the implementation.</p><p>Basically<strong><em>, </em></strong>Publisher<em> </em>creates a subscription when it is requested using its protocol implementation. Through this subscription, subscriber receives the events that has been demanded by itself. Briefly, Publisher and subscriber interact with each other through this subscription object. While interacting each other, they apply back pressure using demand<strong> </strong>requests on the subscription after then they are processed manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*ep7wEiuakVAzRzALmPzEzQ.png" /><figcaption>concept image is taken from <a href="https://www.donnywals.com/understanding-combines-publishers-and-subscribers/">donnywals.com</a></figcaption></figure><p>Other concepts about Combine are <em>Operators </em>and <em>Subjects.</em></p><p><em>Operators</em> are the functions that compose the underlying publisher; such as <em>merge, zip and prefix </em>operators.</p><p><em>Subjects</em> are the special case publishers that conform the Subject protocol and in a way they are both publisher and subscriber at the same time. Such as <em>CurrentValueSubject</em> and <em>PassthroughSubject</em>.</p><p><em>Upstream</em> and <em>Downstream</em> specify the direction of the execution in a chain.</p><pre>     upstream                  downstream<br>source &lt;--- operator (parameters) ---&gt; consumer/further operators</pre><p>For example, <em>subscribe(on:)</em><strong> </strong>without the <em>receive(on:)</em><strong> </strong>operator afterwards, affects both <em>upstream</em>(receiving a subscription, requesting the demand, cancelling the subscription of the upper publisher etc.) and <em>downstream</em>(subscriber and other elements on the chain) execution of the chain. However <em>receive(on:)</em><strong> </strong>operator only affects the downstream execution.</p><p>For the detailed information, you should follow the resource links at the end of the article<a href="https://www.donnywals.com/an-introduction-to-combine/">[1]</a>[<a href="https://www.donnywals.com/understanding-combines-publishers-and-subscribers/">2</a>][<a href="https://developer.apple.com/documentation/combine/processing-published-elements-with-subscribers">3</a>][<a href="https://heckj.github.io/swiftui-notes/">4</a>][<a href="https://medium.com/flawless-app-stories/swift-combine-custom-publisher-6d1cc3dc248f">5</a>]. This post will be about creating a custom takeUntil publisher operator.</p><p>Let’s start with the quick explanation of the prefix operator and then create our custom takeUntil publisher operator.</p><h4>Publishers.PrefixUntilOutput</h4><blockquote>Discard any items emitted by an upstream publisher after a second publisher emits an item.</blockquote><p>This definition except the part that mentions, “takeUntil operator also terminates upstream publisher if second publisher emits termination or error out”<strong> </strong>is taken from the <a href="http://reactivex.io/documentation/operators/takeuntil.html">takeUntil operator definition of ReactiveX</a>. <a href="https://developer.apple.com/documentation/combine/publishers/prefixuntiloutput">PrefixUntilOutput</a> doesn’t implement this feature just as <a href="https://github.com/ReactiveX/RxSwift/issues/763">RxSwift implementation</a> and with our custom takeUntil publisher, we will try to implement it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*46NwzccVe8Sq1pUsItu6Gw.png" /><figcaption>prefix(untilOutputFrom:) operator function works same way as takeUntil operator in RxSwift</figcaption></figure><p>Usage;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7385009a6680a0e4d173f902fe9bc67/href">https://medium.com/media/f7385009a6680a0e4d173f902fe9bc67/href</a></iframe><p>On the above test, downstream subscriber received only [0, 1] values that are sent after the first second. It got completion 2 seconds later by the value which finisher subject sent. Values after that are ignored. Simply, PrefixUntilOutput operator publisher ignores the events after the finisher emits a value.</p><p>However I got some unexpected behaviors on my prefixUntil tests. Based on the used scheduler on the <em>subscribe(on:)</em> method, sometimes there are order of execution problems. Sometimes downstream subscriber couldn’t emit the <em>.finished</em> event because finisher subject emits a value before the downstream subscriber gets a subscription object and sometimes if finisher is set to work on a serial dispatch queue, it could send a completion event without the downstream subscriber gets a subscription object and requests a demand for it.</p><p>It looks like inside the <em>receive(subscriber:)</em> method of the <em>PrefixUntilOutput</em> publisher, finisher and source publishers start before providing a subscription to the downstream subscriber and getting a demand request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dd3e58c1ef8df95e1f4a50ab1e1f7ff/href">https://medium.com/media/6dd3e58c1ef8df95e1f4a50ab1e1f7ff/href</a></iframe><p>In the above test, it emits all values from the source publisher and finally receives a completion event. Finisher publisher doesn’t send any value to the interrupt upstream publisher. However if we want to change our <em>PassthroughSubject</em> with a <em>CurrentValueSubject</em>, then as <em>CurrentValueSubject</em> holds a value initially, we expect our upstream publisher to receive a completion before emitting any value from the source publisher.</p><p>However tests fail sometimes if schedulers that they have called on the <em>subscribe(on:)</em> method, are not properly configured.</p><p>On the above implementation, if we only change the <em>PassthroughSubject</em> with the <em>CurrentValueSubject</em> then all publishers subscribe on the current scheduler which is the main queue. Based on the following output, <em>PrefixUntilOutput</em> publisher starts with the finisher publisher subscription. After the finisher subscription is received, it requests a demand as <em>.max(1)</em><strong> </strong>and receives a value that is defined initially on the <em>CurrentValueSubject</em>. After the emitting value, it tries to send the completion event to the downstream subscriber even before the source and prefixUntil subscriptions are provided. Normally upstream publisher receives a subscription after the source has received its subscription if they all run on the serial schedulers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87571d7b52157f2fd826a1fde1f82fe0/href">https://medium.com/media/87571d7b52157f2fd826a1fde1f82fe0/href</a></iframe><p>In the current implementation of the <em>PrefixUntilOutput</em> publisher, it immediately tries to send the finished event to the downstream subscriber. However, even the downstream subscriber<strong> </strong>emits a completion on this case; if we set schedulers on <em>source</em> and <em>upstream publishers</em> using the <em>subscribe(on:)</em> method, then the downstream subscriber doesn’t emit the completion event because it has not received a subscription yet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c54f6a075a9dfce0da399b06e6950c5d/href">https://medium.com/media/c54f6a075a9dfce0da399b06e6950c5d/href</a></iframe><p>Output;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1aa64f40e137620c4c8a0026b7629359/href">https://medium.com/media/1aa64f40e137620c4c8a0026b7629359/href</a></iframe><p>Finisher starts the subscription on a scheduler that is set by the upstream publisher, and couldn’t send a finished event to the downstream subscriber successfully.</p><p>It is a really weird edge case that can create problems if the upstream execution doesn’t satisfy the timing.</p><p>Let’s create our custom publisher that solves this problem and adds additional feature that completes the upstream publisher if the finisher receives the <em>finished</em> or <em>failure</em> events.</p><h3>Publishers.TakeUntil (Custom Publisher Operator)</h3><p>This custom operator will terminate if it emits any items, completion or failure events from a second publisher.</p><p>Let’s dive in;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8364d138cb5b88a93b1ddb4abe7de3c/href">https://medium.com/media/a8364d138cb5b88a93b1ddb4abe7de3c/href</a></iframe><p>When subscribe methods are<em> </em>called on the publisher, <em>receive(subscriber:)</em> method is called by Combine to provide a subscription to the downstream subscriber.</p><p>Unlike the <em>prefixUntil</em> implementation, I tried to provide a subscription to the downstream subscriber first and after getting an initial demand, started the subscriptions of the <em>source</em> and <em>finisher</em> publishers. Thus, this has fixed the edge case that I described earlier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec38d7b745713b6eb27b511864c869fc/href">https://medium.com/media/ec38d7b745713b6eb27b511864c869fc/href</a></iframe><p>Subscription starts with a <em>waiting</em> state and after the first demand request, it executes the subscribe methods on the <em>finisher</em> and <em>source</em> publishers respectively. Before the subscribe method execution of the source, finisher could set the state to.<em>completed </em>if it was run synchronously. So in that case, we don’t need to start the source subscription to emit values, because downstream subscriber has already received a completion.[Lines 41-89]</p><p>After initial setup, requesting demands will be redirected onto the source demandable subscriber. if the source is still on the subscribed state, it will be executed. [Lines 89–96]</p><p>When creating a custom publisher, we need to be aware of the concurrent executions so using locks on the state changes ensures that events are processed atomically. Also we need to be sure to run side-effects on the outside locks to prevent deadlocks.</p><p>Lets create an operator function extension now to use this publisher as function;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b32f0fb1b86041591da40e4b113ef56c/href">https://medium.com/media/b32f0fb1b86041591da40e4b113ef56c/href</a></iframe><p>Using this extension we could access the <em>TakeUntil</em> publisher using <em>take(until:) </em>operator function.</p><p>Simple usage;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da02b88e47593d21a0f32fe8d90af9b4/href">https://medium.com/media/da02b88e47593d21a0f32fe8d90af9b4/href</a></iframe><p>Finisher sends a <em>.finished</em> event to complete the upstream publisher. Using this operator publisher, you could have some generic functions that can be chained with the upstream publisher and complete the execution by just sending <em>.finished</em> or <em>.failure </em>events without knowing the type.</p><p>You could access above implementation from <a href="https://github.com/hsncr/Combine-TakeUntil"><strong>this repository</strong></a></p><h3><strong>Takeaways</strong></h3><p>It is really a huge step forward by Apple to implement a reactive programming paradigm into its core and that’s for sure that Combine will be an essential component of iOS development in coming years.</p><p>Whether Apple doesn’t recommend creating custom publishers, the framework could have missing parts when you try to implement use-cases. Creating a custom publishers from scratch is one way to overcome it. I hope that using this article, you will manage to solve that problem.</p><p>Let me know if you have any feedbacks or comments on the subject.</p><p>Don’t forget to join <a href="https://combine.community/"><strong>Combine community</strong></a><strong> </strong>on Slack.</p><p>Thanks for reading.</p><h4>Resources</h4><p><a href="https://www.cocoawithlove.com/blog/twenty-two-short-tests-of-combine-part-1.html">https://www.cocoawithlove.com/blog/twenty-two-short-tests-of-combine-part-1.html</a></p><p><a href="https://www.donnywals.com/understanding-combines-publishers-and-subscribers/">https://www.donnywals.com/understanding-combines-publishers-and-subscribers/</a></p><p><a href="https://developer.apple.com/documentation/combine/processing-published-elements-with-subscribers">https://developer.apple.com/documentation/combine/processing-published-elements-with-subscribers</a></p><p><a href="https://medium.com/flawless-app-stories/swift-combine-custom-publisher-6d1cc3dc248f">How to create custom Publisher in Combine</a></p><p><a href="https://www.vadimbulavin.com/understanding-schedulers-in-swift-combine-framework/">https://www.vadimbulavin.com/understanding-schedulers-in-swift-combine-framework/</a></p><p><a href="https://heckj.github.io/swiftui-notes/">https://heckj.github.io/swiftui-notes/</a></p><p><a href="https://www.donnywals.com/an-introduction-to-combine/">https://www.donnywals.com/an-introduction-to-combine/</a></p><ul><li><a href="https://developer.apple.com/documentation/combine/publishers/prefixuntiloutput">Apple Developer Documentation</a></li><li><a href="https://developer.apple.com/documentation/combine/fail/receive(on:options:)">Apple Developer Documentation</a></li></ul><p><a href="https://developer.apple.com/documentation/combine/publisher/subscribe(on:options:)">https://developer.apple.com/documentation/combine/publisher/subscribe(on:options:)</a></p><p><a href="https://github.com/ReactiveX/RxSwift/issues/763">takeUntil does not stop on .Completed · Issue #763 · ReactiveX/RxSwift</a></p><p><a href="https://programmer.group/introduction-to-ios-multi-thread-locks.html">https://programmer.group/introduction-to-ios-multi-thread-locks.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c71ed7551ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[StoryboardLoadable]]></title>
            <link>https://hsnxcr.medium.com/storyboardloadable-a75c55763381?source=rss-39fa2948b849------2</link>
            <guid isPermaLink="false">https://medium.com/p/a75c55763381</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[protocol]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Hasan Acar]]></dc:creator>
            <pubDate>Tue, 15 Dec 2020 19:47:42 GMT</pubDate>
            <atom:updated>2022-03-27T22:22:15.557Z</atom:updated>
            <content:encoded><![CDATA[<p>Using custom initializers inside view controllers on iOS 13 or later.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%252876%252C89%252C104%252C1%2529%26t%3Dpanda-syntax%26wt%3Dnone%26l%3Dswift%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dpublic%252520protocol%252520StoryboardLoadable%252520%25257B%25250A%252520%252520%252520%252520%25250A%252520%252520%252520%252520static%252520var%252520identifier%25253A%252520String%252520%25257B%252520get%252520%25257D%25250A%252520%252520%252520%252520%25250A%252520%252520%252520%252520static%252520var%252520storyboard%25253A%252520UIStoryboard%252520%25257B%252520get%252520%25257D%25250A%252520%252520%252520%252520%25250A%252520%252520%252520%252520static%252520func%252520load%25253CT%25253A%252520UIViewController%25253E%2528creator%25253A%252520%252540escaping%252520%2528%2528NSCoder%2529%252520-%25253E%252520T%25253F%2529%2529%252520-%25253E%252520T%25250A%25257D%25250A%25250A%25252F%25252F%252520MARK%25253A%252520Default%252520implementations%25250Apublic%252520extension%252520StoryboardLoadable%252520%25257B%25250A%252520%252520%252520%252520%25250A%252520%252520%252520%252520static%252520var%252520identifier%25253A%252520String%252520%25257B%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520String%2528describing%25253A%252520self%2529%25250A%252520%252520%252520%252520%25257D%25250A%252520%252520%252520%252520%25250A%252520%252520%252520%252520static%252520func%252520load%25253CT%25253A%252520UIViewController%25253E%2528creator%25253A%252520%252540escaping%252520%2528%2528NSCoder%2529%252520-%25253E%252520T%25253F%2529%2529%252520-%25253E%252520T%252520%25257B%25250A%252520%252520%252520%252520%252520%252520%252520%252520storyboard.instantiateViewController%2528identifier%25253A%252520identifier%25252C%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520creator%25253A%252520creator%2529%25250A%252520%252520%252520%252520%25257D%25250A%25257D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%25252876%25252C89%25252C104%25252C1%252529%26t%3Dpanda-syntax%26wt%3Dnone%26l%3Dswift%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dpublic%25252520protocol%25252520StoryboardLoadable%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520static%25252520var%25252520identifier%2525253A%25252520String%25252520%2525257B%25252520get%25252520%2525257D%2525250A%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520static%25252520var%25252520storyboard%2525253A%25252520UIStoryboard%25252520%2525257B%25252520get%25252520%2525257D%2525250A%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520static%25252520func%25252520load%2525253CT%2525253A%25252520UIViewController%2525253E%252528creator%2525253A%25252520%25252540escaping%25252520%252528%252528NSCoder%252529%25252520-%2525253E%25252520T%2525253F%252529%252529%25252520-%2525253E%25252520T%2525250A%2525257D%2525250A%2525250A%2525252F%2525252F%25252520MARK%2525253A%25252520Default%25252520implementations%2525250Apublic%25252520extension%25252520StoryboardLoadable%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520static%25252520var%25252520identifier%2525253A%25252520String%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520String%252528describing%2525253A%25252520self%252529%2525250A%25252520%25252520%25252520%25252520%2525257D%2525250A%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520static%25252520func%25252520load%2525253CT%2525253A%25252520UIViewController%2525253E%252528creator%2525253A%25252520%25252540escaping%25252520%252528%252528NSCoder%252529%25252520-%2525253E%25252520T%2525253F%252529%252529%25252520-%2525253E%25252520T%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520storyboard.instantiateViewController%252528identifier%2525253A%25252520identifier%2525252C%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520creator%2525253A%25252520creator%252529%2525250A%25252520%25252520%25252520%25252520%2525257D%2525250A%2525257D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8240a468ec99f1b6e6882abb6869688/href">https://medium.com/media/b8240a468ec99f1b6e6882abb6869688/href</a></iframe><p>Using this protocol, we can now initialize our view controllers without the force unwrapping its properties while using storyboards.</p><p><strong>Force unwrapping(!)</strong> is extracting the value of an optional and assuring compiler for it to have value. However this process has its downsides on runtime and crashes application if accessed value is nil.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%252876%252C89%252C104%252C1%2529%26t%3Dpanda-syntax%26wt%3Dnone%26l%3Dswift%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dextension%252520MalignantViewController%25253A%252520StoryboardLoadable%252520%25257B%25250A%252520%252520%252520%252520%25250A%252520%252520%252520%252520public%252520static%252520var%252520storyboard%25253A%252520UIStoryboard%252520%25257B%25250A%252520%252520%252520%252520%252520%252520%252520%252520UIStoryboard%2528name%25253A%252520%252522Malignant%252522%25252C%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520bundle%25253A%252520Bundle%2528for%25253A%252520MalignantViewController.self%2529%2529%25250A%252520%252520%252520%252520%25257D%25250A%25257D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%25252876%25252C89%25252C104%25252C1%252529%26t%3Dpanda-syntax%26wt%3Dnone%26l%3Dswift%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dextension%25252520MalignantViewController%2525253A%25252520StoryboardLoadable%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520public%25252520static%25252520var%25252520storyboard%2525253A%25252520UIStoryboard%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520UIStoryboard%252528name%2525253A%25252520%25252522Malignant%25252522%2525252C%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520bundle%2525253A%25252520Bundle%252528for%2525253A%25252520MalignantViewController.self%252529%252529%2525250A%25252520%25252520%25252520%25252520%2525257D%2525250A%2525257D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6e1b68f1cefc2910834bda1cec4c479/href">https://medium.com/media/f6e1b68f1cefc2910834bda1cec4c479/href</a></iframe><p>Our view controller is inside <em>Malignant.storyboard</em> and its storyboard ID is same as its name which is <em>MalignantViewController</em>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%252876%252C89%252C104%252C1%2529%26t%3Dpanda-syntax%26wt%3Dnone%26l%3Dswift%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfinal%252520public%252520class%252520MalignantViewController%25253A%252520UIViewController%252520%25257B%25250A%252520%252520%25250A%252520%252520private%252520let%252520viewModel%25253A%252520MalignantViewModel%25250A%252520%252520%25250A%252520%252520public%252520init%25253F%2528coder%25253A%252520NSCoder%25252C%252520viewModel%25253A%252520MalignantViewModel%2529%252520%25257B%25250A%252520%252520%252520%252520%252520%252520self.viewModel%252520%25253D%252520viewModel%25250A%252520%252520%252520%252520%252520%252520super.init%2528coder%25253A%252520coder%2529%25250A%252520%252520%25257D%25250A%252520%252520%252520%252520%25250A%252520%252520%25252F%25252F%252520required%252520init%252520coder%252520...%25250A%25257D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%25252876%25252C89%25252C104%25252C1%252529%26t%3Dpanda-syntax%26wt%3Dnone%26l%3Dswift%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfinal%25252520public%25252520class%25252520MalignantViewController%2525253A%25252520UIViewController%25252520%2525257B%2525250A%25252520%25252520%2525250A%25252520%25252520private%25252520let%25252520viewModel%2525253A%25252520MalignantViewModel%2525250A%25252520%25252520%2525250A%25252520%25252520public%25252520init%2525253F%252528coder%2525253A%25252520NSCoder%2525252C%25252520viewModel%2525253A%25252520MalignantViewModel%252529%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520self.viewModel%25252520%2525253D%25252520viewModel%2525250A%25252520%25252520%25252520%25252520%25252520%25252520super.init%252528coder%2525253A%25252520coder%252529%2525250A%25252520%25252520%2525257D%2525250A%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%2525252F%2525252F%25252520required%25252520init%25252520coder%25252520...%2525250A%2525257D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee517d184c75c52df034a6a3daf3b12f/href">https://medium.com/media/ee517d184c75c52df034a6a3daf3b12f/href</a></iframe><p>Now we could use our custom initializer to inject our view model into the view controller and use it to push onto navigation stack.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%252876%252C89%252C104%252C1%2529%26t%3Dpanda-syntax%26wt%3Dnone%26l%3Dswift%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dlet%252520viewModel%252520%25253D%252520MalignantViewModel%2528initialEvent%25253A%252520.idle%2529%25250Alet%252520viewController%252520%25253D%252520MalignantViewController.load%252520%25257B%252520coder%252520in%25250A%252520%252520%252520%252520MalignantViewController%2528coder%25253A%252520coder%25252C%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520viewModel%25253A%252520viewModel%2529%25250A%25257D%25250A%252520%252520%252520%252520%252520%252520%252520%252520%25250Arouter.push%2528viewController%25252C%252520animated%25253A%252520true%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%25252876%25252C89%25252C104%25252C1%252529%26t%3Dpanda-syntax%26wt%3Dnone%26l%3Dswift%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dlet%25252520viewModel%25252520%2525253D%25252520MalignantViewModel%252528initialEvent%2525253A%25252520.idle%252529%2525250Alet%25252520viewController%25252520%2525253D%25252520MalignantViewController.load%25252520%2525257B%25252520coder%25252520in%2525250A%25252520%25252520%25252520%25252520MalignantViewController%252528coder%2525253A%25252520coder%2525252C%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520viewModel%2525253A%25252520viewModel%252529%2525250A%2525257D%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525250Arouter.push%252528viewController%2525252C%25252520animated%2525253A%25252520true%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/37c86fb8a27e45e0468c11e2b83d6c52/href">https://medium.com/media/37c86fb8a27e45e0468c11e2b83d6c52/href</a></iframe><h3><strong>Done</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*y6Rxu4C3R3AQn25JRklPKg.png" /></figure><h3><strong>Takeaways</strong></h3><p>Apple introduced <em>instantiateViewController(identifier:creator:) </em>method on iOS 13 and before that people were using force unwrapping or optional types on properties while using storyboards. As I mentioned above, there are downsides of using force unwrapping. And defining non-optional type as optional fails the API contract.</p><p>Using this protocol you can define and create view controllers with an ease; Also, you will define clear boundaries on your API.</p><p>Thanks for reading.</p><h4><strong>References</strong></h4><ul><li><a href="https://developer.apple.com/documentation/uikit/uistoryboard/3213989-instantiateviewcontroller">https://developer.apple.com/documentation/uikit/uistoryboard/3213989-instantiateviewcontroller</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a75c55763381" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>