<?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 Arkadi Yoskovitz on Medium]]></title>
        <description><![CDATA[Stories by Arkadi Yoskovitz on Medium]]></description>
        <link>https://medium.com/@arkadi.yoskovitz?source=rss-8b4bac280172------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Arkadi Yoskovitz on Medium</title>
            <link>https://medium.com/@arkadi.yoskovitz?source=rss-8b4bac280172------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 05:13:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arkadi.yoskovitz/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[Asi, you need to add a stability requierment to the article.]]></title>
            <link>https://medium.com/@arkadi.yoskovitz/asi-you-need-to-add-a-stability-requierment-to-the-article-5661398266c2?source=rss-8b4bac280172------2</link>
            <guid isPermaLink="false">https://medium.com/p/5661398266c2</guid>
            <dc:creator><![CDATA[Arkadi Yoskovitz]]></dc:creator>
            <pubDate>Sun, 24 Oct 2021 14:51:35 GMT</pubDate>
            <atom:updated>2021-10-24T14:51:35.347Z</atom:updated>
            <content:encoded><![CDATA[<p>Asi, you need to add a stability requierment to the article.</p><p>A SDK should be stable, and should not use experimental theatures.</p><p>It should also has as litel external dependencies as possiable.</p><p>Also you should seperate performance and Scalability, they are two diffrent elements of a system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5661398266c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Refactoring AppDelegate]]></title>
            <link>https://medium.com/@arkadi.yoskovitz/refactoring-appdelegate-189588e34c59?source=rss-8b4bac280172------2</link>
            <guid isPermaLink="false">https://medium.com/p/189588e34c59</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[services]]></category>
            <dc:creator><![CDATA[Arkadi Yoskovitz]]></dc:creator>
            <pubDate>Sat, 25 Aug 2018 17:19:47 GMT</pubDate>
            <atom:updated>2018-08-26T07:03:24.648Z</atom:updated>
            <content:encoded><![CDATA[<h4>service-oriented approach</h4><p>Note: the sample code for this article is in swift.</p><p>All applications have a single root object, on apples’ platforms this object is generally unavailable for developer usage. We as developer don’t have access to the UIApplication object, it’s unavailable for modification and for a good reason.</p><p>Therefor we as developers use a dedicated object as Single Point of Contact to interfere in the global behavior of the application.</p><p>On apples’ platforms this object is the Application Delegate, usually called AppDelegate and mark as such by a custom <a href="https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#UIApplicationMain">attribute</a> . The main task of this object is to implement the UIApplicationDelegate protocol, as this protocal is used by the OS to determine if and how the app should respond to different system wide events.</p><h4>TL;DR;</h4><h4>Problem Statement</h4><p>The Application Delegate is the root object of your app. It ensures the app interacts properly with the system and with other apps. It’s very common for an app to handle multiple different use cases, such as push notification, deeplink, 3D touch, WatchKit or CloudKit integration or simply state restoration.</p><p>All these responsibilities make it difficult object to maintain and test.</p><p>If this sounds familiar you are not alone, many great apps have the issue and most try to handle it the same way, which means not at all.</p><p>A bit like the currently popular joke between developers that the MVC pattern is actually Massive ViewController.</p><p>The problem in both cases is the same: a <em>lake of knowledge or skill on the developer side.</em></p><p>For some unknown reason we expect apple’s technical samples (which are meant to demonstrate how to use certain API’s) to be educational app architecture instructions. But this is a topic for a different blogpost …</p><p>Back to our current issue.</p><p>Most developers which face this issue try to handle it in one of several ways:</p><ol><li>Massive AppDelegate — basically do nothing, just keep on adding more content to the class, usually in the same file, and in the same scope.</li><li>Massive AppDelegate with extensions —the same as option 1, but split the methods into separate extensions, usually in the same file. Because we cant redeclare protocol conformance.</li><li>Mediator AppDelegate — A different approach where we implement all relevant protocol methods the AppDelegate class but the implementation calls on additional control objects to handle sub content, usually by topic. This approach retains the problem and is only useful as a way to minimize the code presence in the AppDelegate class.</li><li>Some combination of options 2 &amp; 3.</li></ol><p>All of these approaches are problematic and none really give a good simple solution to our problem.</p><blockquote><strong>An old Chinese proverb:</strong><br>It is said that if you know your enemies and know yourself,<br>you will not be imperiled in a hundred battles;<br>If you do not know your enemies but do know yourself,<br>you will win one and lose one;<br>If you do not know your enemies nor yourself,<br>you will be imperiled in every single battle.</blockquote><p>So who is our enemy in this case? The App? The OS implementation? Our lake of knowledge of the “correct way”? Should we open a bunch of radars and implore Apple to fundamentally change the design of the OS? Should we except that we have no way to defeat our enemy?</p><p>The first step to defeat your enemy, is to know it. Or in our case, to define the problem we’re trying to solve.</p><p>The problem that we are facing is not necessary related to the length of code needed to handle all of the different aspects of global app management.</p><p>It is the fact that we have no simple way to maintain and test it.</p><p>But as any developer knows that is what we have architecture and design for. We could write an app in a single GOD class which will handle all use cases contained in the app, but we don&#39;t.</p><p>We use OOP , POP and a bunch more acronyms to split our code as a way to manage it via different logic contracts as a way to represent our complex system in a simple way.</p><p>So what can we do to simplify our current problem? Split the class responsibility of course.</p><p>The question is How? Some take the naive approach, and say we MUST do all of our code in the AppDelegate class and it must be a subclass of UIResponder, this is after all that Apples’ template creates for us:<br><em>A new file containing a class which is called AppDelegate, inherits from UIResponder, implements the UIApplicationDelegate protocol and is marked by the </em>UIApplicationMain attribute.</p><p>Do we have to do that? Of course not.</p><p>Any class can be marked with the UIApplicationMain attribute. It can called anything we wish. It does not event have to be a UIResponder (although the system expects it to be).</p><p>We do have to mark our class as conforms to <em>UIApplicationDelegate (this is a constraint of the UIApplicationMain attribute)</em>, but as the protocol only contains optional methods we aren’t constraint in any major way.</p><p>Which is great and all, but doesn’t really solve anything, or relate to the solution.</p><h3>A different approach</h3><p>As part of the general architecture hype many developer try to work according to the <a href="https://en.wikipedia.org/wiki/SOLID">SOLID</a> principles, the first of which is the <a href="https://en.wikipedia.org/wiki/Single_responsibility_principle">Single responsibility principle</a></p><p>Which begs the question what is the SR of the ApplicationDelegate, should it be responsible for some actions? handle some events and delegate some to a different entity?</p><p>Our app needs a way to do many thinks some of which are:</p><ul><li>Initialize numerous third-party libraries &amp; Conform to their delegate protocols</li><li>Mange and configure a logger for the app</li><li>Initialize persistence stack and manage migrations as needed</li><li>Handle 3D Touch quick actions</li><li>Manage notifications: request permissions, store token, handle custom actions, propagate notifications to the rest of the app</li><li>Configure UIAppearance</li><li>Manage analytics</li><li>Manage device orientation</li><li>Manage background tasks</li></ul><p>lets take a step back from our problem and try to imagine how we would have build our system if we weren’t constraint in any way.</p><p>Our app needs a different entity to handle each of the those separately.</p><p>Imagine we split the responsibility of the ApplicationDelegate into several different objects each encapsulate their own distinct responsibility, be it PushNotification, deep link handling or any other. This is something that we can do it’s not that difficult to create new classes (we do it all the time after all).</p><p>Now that we have our different objects , lets call them <a href="https://en.wikipedia.org/wiki/Service-oriented_architecture">service (it’s what they are after all)</a>. Each service class will confirm to UIApplicationDelegate as if it’s the only class that implements the protocol, handling only call backs that it needs, that way we split the callback handing code into separate distinct entities.</p><p>Next, we need connect these entities together into a single system? We can’t split the OS functionality that is a hard constraint, so what do we do?</p><p>We use the Proxy pattern to sent the relevant method calls to their destinations, but with a twist.<br>Instead of simply using a proxy to forward a method call to a single real destination, we split forward the method calls and send them to multiple entities as needed, basically creating a dispatch mechanism to forward each method call to a repository of service objects. After implementing this functionality we push it all into a separate class, this will be our base class, that way the actual AppDelegate will inherent all the dispatch functionality. This means that we only need to override the service repository in the actual AppDelegate class.</p><p>Something along those lines way proposed and it’s not all that new of an idea, see links below:</p><blockquote>Unfortunately i am unable to locate the original Obj-C implement sample but take a look at the later Swift implementation related articles</blockquote><blockquote><a href="http://www.vadimbulavin.com/refactoring-massive-app-delegate/">http://www.vadimbulavin.com/refactoring-massive-app-delegate/</a><br><a href="https://medium.com/ios-os-x-development/pluggableapplicationdelegate-e50b2c5d97dd">https://medium.com/ios-os-x-development/pluggableapplicationdelegate-e50b2c5d97dd</a></blockquote><p>As they say, the devil is in the details. Let us take a look at some issues that we faced:</p><ol><li>Each service implements the relevant method calls from the UIApplicationDelegate protocol, along with its own inner logic. Multiple classes can conform to the same protocol so this is not a problem.</li><li>The AppDelegate is used as a container, which holds the active services, and as a dispatcher to forward the method calls.</li><li>The AppDelegate base class is used as a dispatcher to forward the method calls. Again this is not a problem.</li><li>Some methods must return and we cant simply forward the method call, such as “application:didFinishLaunchingWithOptions:”. Via a smart implementation of the dispatch action we can handle this use case in such a way that we will alway rerun an answer to the OS, ether a default implementation, or a custom replay from one of the service objects.</li><li>System starts to complain for specific method calls if where’s no implementation or if certain info.plist key are missing (i.e: background mode, cloud kit) this is an open issue.</li></ol><p>As you can see most issues were resolved already by other developer.</p><p>The only real problem is issue 5, but what a problem, several different developer tried to handle this and so far no luck. The usual way to solve this was by commenting out methods that are not needed in order to resolve these system issues and to prevent weird behavior of the OS for partial implementations.</p><h3>The wonders of dynamic method dispatch</h3><p>This is where the uniqueness of Apples’ platform comes into play. All method calls are basicly a call to objc_message, each with a diffrent Selector (SEL the method name) &amp; method implementation (The IMP block). As part of the standard mechanisem to handle sending method messages in the app uses the method “responds(to:)”, with a bit fo creative logic we can adapt it to check for incoming selector implementation in the services repository.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52a43ae39599b86533acbc1335b40efc/href">https://medium.com/media/52a43ae39599b86533acbc1335b40efc/href</a></iframe><h3>Conclusion</h3><p>That’s all. A bit of runtime magic and an extension to an existing solution and we get a reusable frame work which allows us a simple way to decouple the AppDelegate object from it’s many responsibilities, preventing it to become a mess.</p><p>For full information see my github repository here:</p><p><a href="https://github.com/ArkadiYoskovitz/A4SAppDispatcherKit">https://github.com/ArkadiYoskovitz/A4SAppDispatcherKit</a></p><p>I hope this will help you as much as me. I really want to have some feedback about this. Please, leave your comments bellow 👇🏼</p><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=189588e34c59" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>