<?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 Shahrukh Alam on Medium]]></title>
        <description><![CDATA[Stories by Shahrukh Alam on Medium]]></description>
        <link>https://medium.com/@alam.shahrukh786?source=rss-4560785bf7b6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lNwe_8qkNEz8B_uO</url>
            <title>Stories by Shahrukh Alam on Medium</title>
            <link>https://medium.com/@alam.shahrukh786?source=rss-4560785bf7b6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 23:54:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alam.shahrukh786/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[Simplest Networking Layer in iOS]]></title>
            <link>https://medium.com/swift2go/simplest-networking-layer-in-ios-58193fe562c8?source=rss-4560785bf7b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/58193fe562c8</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Shahrukh Alam]]></dc:creator>
            <pubDate>Tue, 28 Sep 2021 10:38:15 GMT</pubDate>
            <atom:updated>2021-10-03T03:02:56.274Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a minimalistic approach to what we call the Networking Layer in iOS Development. We will try to look at it in the most logical &amp; simplest way.</p><blockquote>Code should be simple, not clever -Anonymous</blockquote><h4>Typical Networking Stack</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aK2yesvctglI041b6O3IJQ.png" /><figcaption>Credits: <a href="https://developer.apple.com/videos/play/wwdc2018/417/">Testing Tips &amp; Tricks WWDC 2018/417</a></figcaption></figure><h4>Typical Networking Layer</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r3ZJqaBFg_CiBBoLAP5cLA.png" /><figcaption>Typical Distributed Networking Layer Architecture</figcaption></figure><h3>Retrospection</h3><blockquote>If you define the Problem correctly, you almost have the Solution -Steve Jobs</blockquote><p>Let’s take a step back &amp; think logically with some basic questions:</p><h4>Did we think of anything simpler before writing those Protocols</h4><p>You often hear this “Let’s start with a Protocol”. But, Why?</p><p>Swift encourages Protocol Oriented Programming, but that doesn’t mean only that. For instance, if you know Protein is good for your health, that doesn’t mean you won’t intake Carbs, Fats or Water for that matter.</p><h4>Is it a real use case of Protocols</h4><p>You often hear this “Protocols mean good code”. But, Why?</p><p>Protocols are great for polymorphic code, <a href="https://www.youtube.com/watch?v=wfMtDGfHWpA">composition over inheritance</a> (by <a href="https://twitter.com/mpjme">Mattias Petter Johansson</a>), abstraction &amp; Testability. But, when we are dealing with value (not behavior), so abstraction or composition over inheritance is not needed/related. Then we should ask if we really have polymorphs, I mean do we have a case of Cats &amp; Dogs or we are just creating a Pet from its head, body &amp; tail.</p><p>Great watch for the right use case of Protocol: <a href="https://www.dotconferences.com/2016/01/rob-napier-beyond-crusty-real-world-protocols">Beyond Crusty: Real-World Protocols</a> by <a href="https://www.twitter.com/cocoaphony">Rob Napier</a></p><h4>Are the Protocols really adding a value</h4><p>You often hear this “We might need it in the future”. But, who has seen the future?</p><p>Protocols for values encourage predicting the future much like Inheritance. For something really simple, we sometimes end up creating too many Generics with a higher barrier of entry &amp; too many concrete types which would impact the compile time. Also starting with a Protocol puts you in a spiral trap of adding more of them. Few things to keep in mind about the Network Layer:</p><ul><li>Is your team including junior devs know the in &amp; outs of it?</li><li>Are they comfortable with the level of Generics in it?</li><li>Do they think it’s bulkier than it should be?</li></ul><p>A great read for not to use Protocol: <a href="https://www.swiftindepth.com/2019-03-24/a-case-of-premature-abstractions">A case of premature abstractions</a> by <a href="https://www.twitter.com/tjeerdintveen">Tjeerd</a></p><h3>Inspection</h3><p>Typical Networking Layer is great for Distribution, Testability &amp; Ease of Use. But, I think it lacks Readability or rather too much to read for something trivial like creating URLRequests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uc20KUbY_6DjErlvcBBwOQ.png" /><figcaption>Fundamental Types needed for Networking | Credits: <a href="https://matteomanferdini.com/network-requests-rest-apis-ios-swift/">matteomanferdini.com</a></figcaption></figure><h4>Power of Extension</h4><p>I think instead of creating 10s &amp; 100s of concrete APIRequest types, we can achieve the same thing with simple extensions without even sacrificing Distribution, Testability &amp; Ease of Use.</p><ol><li>Let’s first create the <em>URL</em>. We would use <em>URLComponents</em> as it offers a more flexible way for the same.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*re1tiwb-6F-Ms6eAIMqDdw.png" /></figure><p>Now, the client can use this simple extension to create <em>URLComponents </em>as per the API requirements extending itself:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aq-yQaMAovm3K-wbP5sFFA.png" /></figure><p>And just like that, we have our <em>URL</em> from <em>URLComponents</em>.</p><p>2. Next let’s add HTTPMethod, HTTPBody &amp; HTTPHeaders. Again we use an extension on <em>URLRequest </em>along with builder pattern to modify the <em>URLRequest </em>struct using <em>inout</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CFTCtKjZNSim5fylrdCmhA.png" /></figure><p>Do note we have marked the <em>map</em> function as <em>private </em>as we want clients to create their <em>URLRequest</em> only through the available builder APIs.</p><p>This is how it looks client side:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6v-_vyf1P1qFiJubqlLD6g.png" /></figure><p>Till now, I believe we have not compromised on Distribution, Testability or Ease of Use although one might argue that we have to do 2 things for an API call: creating URComponent &amp; building URLRequest. But, I think they are actually 2 different things.</p><p>On the brighter side, we didn’t end up creating 2 files for 2 API calls: UsersAPIRequest &amp; UserDetailAPIRequest. So, we might not really need that <strong>APIRequest</strong> protocol at all from the Typical Network Layer.</p><p>There is a problem though if we have 100s of API calls, we can’t have all of them in a single extension of URLRequest. We can separate them based on Features (say URLRequest+Users.swift, URLRequest+Articles.swift etc) instead. How you define a Feature is completely up to you.</p><p>And just like that, we have our <em>URLRequest</em>.</p><p>3. Next let’s take the same approach for actual API client:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZyRtaokNM5h5eL2YjvoB7w.png" /></figure><p>And this is how it looks client side:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBx8UtkSZcYDJc20d_RyXA.png" /></figure><p>It looks cool &amp; works with so little code. But, here we have compromised few things:</p><ol><li><strong>Distribution</strong>: On the client side we needed to specify the type of response by AnyPublisher&lt;DetailResponse, Error&gt; which was not the case with <em>APIService</em> from typical Networking Layer as its role was to do just that. Hence we also had to import Combine for Client which adds a Module Dependency, which goes against the <em>Dependency Inversion</em> of SOLID principle.</li><li><strong>Testing: </strong>As we are doing things in an extension of concrete URLSession, it’s difficult to mock it for Unit Testing. If you are the only developer or a small team in a startup, you might get away with it. But, the ROI of Testing in the form of saving time is huge.</li></ol><blockquote>Even the Truth should be tested once -Bangalore Proverb</blockquote><p><strong>W</strong>e can partially solve problem (1) though using MetaType:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cFdxDIi75DlLL62qHmYNKA.png" /></figure><p>Client Side:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BFfASVXME52YjbPhMdv3Bw.png" /></figure><p>To solve problem (2), we might end up creating <em>APIClient</em> similar to typical Networking Layer injecting <em>URLSession</em> so that:</p><ul><li>we can do <a href="https://www.swiftbysundell.com/articles/mocking-in-swift/#partial-mocking">partial mocking</a> of <em>URLSession</em> &amp; <em>URLSessionDataTask</em></li><li>or do <a href="https://www.swiftbysundell.com/articles/mocking-in-swift/#complete-mocking">complete mocking</a> of <em>URLSession </em>abstracting it into something like <em>URLSessionProtocol</em></li></ul><p>Both the above approaches are fine, but they will defeat our purpose of simplifying things. Just to be able to test, we shouldn’t add extra overhead to the production code. Is there a better way?</p><p>It turns out there is. We can get creative taking inspiration from <a href="https://developer.apple.com/videos/play/wwdc2018/417/">Testing Tips &amp; Tricks WWDC 2018/417</a> by mocking <em>URLProtocol</em>.</p><blockquote>URLProtocol is another lower-level API that performs the underlying work of opening network connection, writing the request, and reading back a response. It is designed to be subclassed giving an extensibility point for the URL loading system.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQRwXljeHi1rhbgdKpeJ7g.png" /><figcaption>Native URLSession Design | Credits: <a href="https://developer.apple.com/videos/play/wwdc2018/417/">Testing Tips &amp; Tricks WWDC 2018/417</a></figcaption></figure><p>This is how the mocking looks in code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nK_HAiC_kInFkKvd3ILkHQ.png" /></figure><p>And now we can easily write the <em>APIClient </em>like test without changing any production code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8WgGlJq2Xb-QnTsxpZ68g.png" /></figure><h3>Simplification</h3><p>We are actually done. Now, we have a fully (it depends though) functional Networking layer with just 3 simple extensions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*gCXM_iZx2wqc0IfIWbiYvw.png" /></figure><p>It’s actually so short &amp; sweet that we might not have to extract it into a separate Dynamic Framework which would improve App Launch Time.</p><p>If you are not familiar with Static or Dynamic Frameworks &amp; Libraries, please checkout my previous posts:</p><ul><li><a href="https://medium.com/swift-india/static-library-in-ios-d133123678d1">Static Library in iOS</a></li><li><a href="https://medium.com/swift2go/how-jesse-pinkman-cracked-dynamic-library-in-ios-part-1-c6be383796b1">How Jesse Pinkman Cracked Dynamic Library in iOS (Part 1)</a></li></ul><h3>Justification</h3><p>To measure improvements in Build Time &amp; App Launch Time if any, I have created 2 Apps: the <a href="https://github.com/shahrukhalam/AppUsingTypicalNetworkingLayer">first one</a> with Typical Network Layer (as a Dynamic Framework) with 10 APIRequests &amp; <a href="https://github.com/shahrukhalam/AppUsingSimplestNetworking">second one</a> with our (this) Simple Network Layer (as code) with the same 10 APIRequests. Here are the results on MacBook Air (M1, 2020, 16 GB) with iPhone SE (2nd Generation, iOS 15.0):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dipuK7Nnh_kp7HOTaCTvjg.png" /></figure><p><strong>Note:</strong> There are few criticisms about extensions though w.r.t compilation times, readability &amp; code clarity discussed in <a href="https://minikin.medium.com/benchmark-of-swift-extensions-vs-methods-swift-4-1-may-2018-2df3229f76fe">Benchmark of Swift extensions vs methods</a> by <a href="https://minikin.medium.com/?source=post_page-----2df3229f76fe--------------------------------">Sasha Prokhorenko</a>.</p><h3>Conclusion</h3><p>In this post, we discussed a minimalistic approach to Network Layer in iOS. You could check out the full playground implementation on <a href="https://github.com/shahrukhalam/SimplestNetworking">Github</a>. Obviously, as the project grows one would need more things, but the ideology remains the same.</p><blockquote>Start simple, adapt, Evolve -SA</blockquote><p>It highlights few points against the heavy or unnecessary use of Protocols from the very beginning. It also encourages leveraging the power of extensions. Don’t hesitate to extend the native types before creating your own type.</p><p>Although these things are debatable, it is making a clear point that we should write code with care. Even the most junior dev shouldn’t think twice before checking out the Network Layer. Please let me know what you think in the comments below.</p><p>Happy Coding &amp; Sharing 😍<br>Cheers 🍺<br><a href="https://www.linkedin.com/in/alamshahrukh/">Shahrukh Alam</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58193fe562c8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift2go/simplest-networking-layer-in-ios-58193fe562c8">Simplest Networking Layer in iOS</a> was originally published in <a href="https://medium.com/swift2go">Swift2Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Jesse Pinkman Cracked Dynamic Library in iOS (Part 1)]]></title>
            <link>https://medium.com/swift2go/how-jesse-pinkman-cracked-dynamic-library-in-ios-part-1-c6be383796b1?source=rss-4560785bf7b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6be383796b1</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Shahrukh Alam]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 17:23:34 GMT</pubDate>
            <atom:updated>2024-01-07T08:34:51.310Z</atom:updated>
            <content:encoded><![CDATA[<h4>Are you Duplicating a piece of code for a particular functionality across multiple Apps? Do you find it difficult to fix a bug in all those places? If Yes, then Dynamic Library is an answer to your problems.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iqRUZBPfr4bCgBrt6AxaKg.jpeg" /><figcaption>Courtesy: <a href="https://www.artstation.com/artwork/XBmkGw">Artstation</a></figcaption></figure><blockquote>this article has been moved <a href="https://unknowndefault.com/dynamic-library-in-ios-part-1">here</a> 😍</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6be383796b1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift2go/how-jesse-pinkman-cracked-dynamic-library-in-ios-part-1-c6be383796b1">How Jesse Pinkman Cracked Dynamic Library in iOS (Part 1)</a> was originally published in <a href="https://medium.com/swift2go">Swift2Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How StackView works]]></title>
            <link>https://medium.com/geekculture/how-stackview-works-861035c72e83?source=rss-4560785bf7b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/861035c72e83</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Shahrukh Alam]]></dc:creator>
            <pubDate>Wed, 21 Jul 2021 22:02:29 GMT</pubDate>
            <atom:updated>2021-07-21T22:02:29.289Z</atom:updated>
            <content:encoded><![CDATA[<h3>Let’s build YouI StackView</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-1SDO6u6j4XjSz85.jpg" /><figcaption>Credits: <a href="https://www.venetian.com/">The Venetian</a></figcaption></figure><blockquote>When the Odds are stacked against you, use StackView and chill.</blockquote><blockquote>- Pineapple</blockquote><p><strong>Did you know a game of Poker once lasted nearly eight and a half years! <br></strong>Now that I have the most precious gift; your attention, let’s dive straight into what this article is about:</p><p><strong>Audience<br></strong>Beginner, Intermediate<br><strong>What are we building<br></strong>Two labels stacked vertically in a UIView which should autoresize itself based on the content width of the bigger label using pure auto layout:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TjNZuLedeu_TdSSo22dc8A.png" /><figcaption>Fig 1</figcaption></figure><p><strong>What are we not building<br></strong>A StackView implementation from scratch, this is more like an understanding of how auto layout works, which is leveraged in a StackView</p><h3>Iteration 0</h3><p>Let’s try to do what most of us would do as the first attempt:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GgMfN5_VZzGTLHc_xzPdjQ.png" /><figcaption>Fig 2</figcaption></figure><ol><li>Red Label.Leading = Superview.Leading + 20</li><li>Red Label.Top = Superview.Top + 20</li><li><em>Red Label.Trailing + 20 = Superview.Trailing</em></li><li>Blue Label.Top = Red Label.Top + 20</li><li>Blue Label.Leading = Superview.Leading + 20</li><li><em>Blue Label.Trailing + 20 = Superview.Trailing</em></li><li>Blue Label.Bottom = Superview.Bottom + 20</li></ol><p>There is a problem with these set of constraints, both the equations (3) &amp; (6) can’t be satisfied at the same time, which is evident looking at <em>Fig 2</em></p><p>But, what’s interesting is most of the time we get away with it:</p><ul><li>If you are using Storyboard, it would show error &amp; suggest a fix by bumping either of the Labels horizontal content-hugging and compression-resistance priorities (CHCR priorities).<br>Even though it silences the error, it might not be the right solution. Storyboard is pretty smart, but not smart enough to know human needs, in this case we don’t want either of the Labels to grow or shrink.</li><li>If you are creating views programmatically, things might look okay on the simulator as smaller Label will get stretched &amp; there might not be a background color set to it. But we will get breaking constraints log on the console, which honestly we sometimes conveniently ignore.</li></ul><h3>Iteration 1</h3><p>Now that we know constraints are conflicting only on the Trailing side, let’s focus solely on it keeping our requirement in mind.</p><p>But, before we do that there is a catch in <em>Fig 2</em>, two set of constraints (for both <em>Width</em> &amp; <em>Height</em>) are not visible to us, which gets added by layout engine automatically for all the views with intrinsic content size. We will focus on the set of constraints for <em>Width </em>as it would help us resolve the conflicting constraints on the Trailing side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/0*Vksmd2ZlfhTsdTtS.png" /><figcaption>Fig 3: Content Hugging &amp; Compression | Credits: <a href="https://developer.apple.com/">Apple</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OdoDcYGPCPvwe7_lBCFHeg.png" /><figcaption>Fig 4</figcaption></figure><p>Layout engine adds following set of constraints for Label’s <em>Width</em>:</p><p><em>For Content Hugging:</em><br>Label.width ≤ 0.0 * NotAnAttribute + IntrinsicWidth <strong><em>(Priority: 250)</em></strong></p><p><em>For Compression Resistance:</em><br>Label.width ≥ 0.0 * NotAnAttribute + IntrinsicWidth <strong><em>(Priority: 750)</em></strong></p><p>If you are wondering why priority is more for Compression Resistance, that’s because iOS doesn’t want our content to be clipped, if it’s getting expanded it’s okay for the user.</p><p>Now that we know about the hidden constraint by layout engine, we can go back to fixing conflicting constraints only on the Trailing side. Let’s take a step back &amp; think it through what we want or what our requirement is:</p><ul><li>If we would take only the smaller Label into account, we need a trailing spacing to be greater than 20</li><li>If we would take only the bigger Label into account, we need a trailing spacing to be equal to 20</li></ul><p>If we could club both of these conditions, we will end up with:</p><ul><li>Both labels will need a trailing spacing to be greater than or equal to 20</li><li>Both labels might need a trailing spacing to be equal to 20, if it can satisfy the layout engine’s set of constraints for <em>Width</em>. Basically, we can set a lower priority <strong>(say 249)</strong> to it than the lowest priority <strong>(250)</strong> of the set of constraints for <em>Width </em>from <em>Fig 4</em>.</li></ul><p><strong>Note:</strong><br>When calculating solutions for the constraint equations:</p><ul><li>Auto Layout attempts to satisfy all the constraints in priority order from highest to lowest.</li><li>If it cannot satisfy an optional constraint <em>(a constraint which is not required; with a non-1000 priority)</em>, that constraint is skipped and it continues on to the next constraint.</li></ul><p>So, Auto Layout will also take into account that both labels might need a trailing spacing to be equal to 20, but it would give more preference to layout engine’s set of constraints for <em>Width</em>. It would keep it if it satisfies other constraints, in our case only bigger label will satisfy.</p><p>This is how trailing constraints in focus will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKMlwkbSKqjP879N_4P2dg.png" /><figcaption>Fig 5</figcaption></figure><ol><li>Red Label.Trailing + 20 = Superview.Trailing<em> </em><strong><em>(Priority: 249)</em></strong></li><li>Superview.Trailing<em> </em>≥ Red Label.Trailing + 20</li><li>Blue Label.Trailing + 20 = Superview.Trailing<em> </em><strong><em>(Priority: 249)</em></strong></li><li>Superview.Trailing<em> </em>≥ Blue Label.Trailing + 20</li></ol><p>For <strong>case 1</strong> in <em>Fig 1</em>, (1) from above can’t be satisfied, but (3) can be. Conversely, for <strong>case 2</strong>, (3) can’t be satisfied, but (1) can be.</p><p>So, the complete working constraints will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xHfxb3FeY5xILz-aESy4Tw.png" /><figcaption>Fig 6</figcaption></figure><ol><li>Red Label.Leading = Superview.Leading + 20</li><li>Red Label.Top = Superview.Top + 20</li><li>Red Label.Trailing + 20 = Superview.Trailing<em> </em><strong><em>(Priority: 249)</em></strong></li><li>Superview.Trailing<em> </em>≥ Red Label.Trailing + 20</li><li>Blue Label.Top = Red Label.Top + 20</li><li>Blue Label.Leading = Superview.Leading + 20</li><li>Blue Label.Trailing + 20 = Superview.Trailing<em> </em><strong><em>(Priority: 249)</em></strong></li><li>Superview.Trailing<em> </em>≥ Blue Label.Trailing + 20</li><li>Blue Label.Bottom = Superview.Bottom + 20</li></ol><h3>Time to code</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e48f3914d95486035f3c758677aed4a0/href">https://medium.com/media/e48f3914d95486035f3c758677aed4a0/href</a></iframe><p>I have made it IBDesignable so that we can see the preview on storyboard by just setting IBInspectable properties. This is how it looks for both the cases from <em>Fig 1</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*orkcrJXHEd9j8Pe3rBst3Q.png" /><figcaption>Fig 7</figcaption></figure><p>The above code of <em>VerticalStack </em>will also work for 2 buttons or 1 label &amp; 1 button, basically for any View which has an intrinsic content size.</p><p><strong>Note:</strong><br>It only handles the <em>Width</em> aspect perfectly as I have purposefully not taken <em>Height</em> into account to keep things simple. But, the concept for handling Height remains similar.</p><h3>Epilogue</h3><p>In this article with the help of a simple usecase of vertical stack of two labels, we discussed:</p><ul><li>How constraints are translated to simple mathematical equations</li><li>How conflicting constraints occur</li><li>How constraints are automatically generated by layout engine for views with intrinsic content size</li><li>What are constraint priorities</li><li>What are content hugging &amp; resistance priorities</li><li>How auto layout resolves constraints with different priorities</li></ul><p>I hope you got an idea on how auto layout thinks &amp; how you should think while laying out views.</p><p>That’s it for now, until next time…</p><p>Happy Coding &amp; Sharing 😍<br>Cheers 🍺<br><a href="https://www.linkedin.com/in/alamshahrukh/">Shahrukh Alam</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=861035c72e83" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/how-stackview-works-861035c72e83">How StackView works</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[7 Reasons why I don’t like Cocoapods]]></title>
            <link>https://medium.com/swift2go/7-reasons-why-i-dont-like-cocoapods-cb02173d3e27?source=rss-4560785bf7b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb02173d3e27</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Shahrukh Alam]]></dc:creator>
            <pubDate>Fri, 22 Jan 2021 10:29:56 GMT</pubDate>
            <atom:updated>2024-01-07T08:58:48.820Z</atom:updated>
            <content:encoded><![CDATA[<p>We all love &amp; use <a href="https://cocoapods.org/">Cocoapods</a> extensively as a <a href="https://medium.com/prodsters/what-are-dependency-managers-26d7d907deb8#:~:text=Dependency%20managers%20are%20software%20modules,use%20configuration%20files%20like%20composer.">Dependency Manager</a>. But, have we taken a step back in introspect if it’s true love or a compromise like any other relationships.</p><p>In this blog, I would give 7 reasons why I have reached a space where I don’t like Cocoapods anymore. To be clear I have nothing against Cocoapods, they have done great work on making iOS Developer&#39;s life easy for a decade. Also, it’s not just about Cocoapods, I feel the points I would highlight is true for any Dependency Manager.</p><h4>1. <a href="https://en.wikipedia.org/wiki/Infinity_mirror">Infinity Mirror</a></h4><p>Like any Developer, I would love to have 100% focus on my Development, but there are situations with Cocoapods which don’t let me do that. Instead, I have to fix some build issues which are sometimes sporadic &amp; out of context.</p><blockquote>this article has been moved <a href="https://unknowndefault.com/7-reasons-why-i-dont-like-cocoapods">here</a> 😍</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb02173d3e27" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift2go/7-reasons-why-i-dont-like-cocoapods-cb02173d3e27">7 Reasons why I don’t like Cocoapods</a> was originally published in <a href="https://medium.com/swift2go">Swift2Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Decoded Function Builders in Swift]]></title>
            <link>https://medium.com/swift-india/how-i-decoded-function-builders-in-swift-be21e9f13429?source=rss-4560785bf7b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/be21e9f13429</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Shahrukh Alam]]></dc:creator>
            <pubDate>Wed, 09 Dec 2020 12:11:00 GMT</pubDate>
            <atom:updated>2020-12-09T12:11:00.260Z</atom:updated>
            <content:encoded><![CDATA[<p>This is my experience with Function Builders in Swift. How I encountered it, the things I did to find behind the scenes which make a Function Builder &amp; ultimately reach the awesomeness of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xQGWp-GgM9LHqfVH6cScaA.jpeg" /><figcaption>Courtesy: <a href="https://wallpapercave.com/domino-wallpapers">WallPaperCave</a></figcaption></figure><p>So, without further ado, let’s begin. I was watching the <a href="https://developer.apple.com/videos/play/wwdc2019/402/"><em>What’s New in Swift</em></a><em> </em>WWDC 2019 video a few months back. I loved a lot of things like <a href="https://docs.swift.org/swift-book/LanguageGuide/Functions.html"><em>Implicit Returns</em></a>, <a href="https://docs.swift.org/swift-book/LanguageGuide/OpaqueTypes.html"><em>Opaque Result Types</em></a> &amp; <a href="https://docs.swift.org/swift-book/LanguageGuide/Properties.html"><em>Property Wrappers</em></a>, but I was blown away by something called Function Builders.</p><p>Because it looked foreign, yet felt so Swifty, let’s me write an HTML <a href="https://en.wikipedia.org/wiki/Domain-specific_language"><em>DSL</em></a><em> </em>in pure swift like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kB4dIOHTHZWwV_BAhb8fhw.png" /><figcaption>Credits: <a href="https://developer.apple.com/videos/play/wwdc2019/402/">WWDC 2019</a></figcaption></figure><p>It felt simply awesome to me for writing a DSL because it brings:</p><ul><li><strong>Syntactic Sugar:</strong> Concise yet Expressive, Clear &amp; Easy to use, basically everything that Swift stands for ❤️</li><li><a href="https://en.wikipedia.org/wiki/Composition_over_inheritance#:~:text=Composition%20over%20inheritance%20(or%20composite,than%20inheritance%20from%20a%20base"><strong>Composition:</strong></a> Encapsulates Hierarchal Heterogeneous Data Structures</li><li><a href="https://en.wikipedia.org/wiki/Declarative_programming#:~:text=Declarative%20programming%20is%20a%20non,by%20a%20declarative%20programming%20style.">Declarative Style</a></li><li><strong>Power of Swift: </strong>Compiler Type Check &amp; Safety, Auto-Complete &amp; Syntax Highlight</li><li>No more Context Switching</li></ul><p>After a few days, I got the chance to write an App as a part of an interview process, completely in SwiftUI which uses the power of Function Builder extensively. Then, I realized that it’s not only awesome, but it’s a killer 💀too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Ud5pnRAB6_fIeUeEHYJww.png" /><figcaption>Credits: <a href="https://developer.apple.com/videos/play/wwdc2019/402/">WWDC 2019</a></figcaption></figure><p>Now that I was completely blown away by it, I was excited to know behind the scenes that make a Function Builder. In the same WWDC video <a href="https://twitter.com/zaks_anna">Anna Zaks </a>from Swift Team nicely explains how a compiler transforms a simple looking closure into a neat-meat code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fQ_KprDLz38Hn8f5QZNblw.png" /><figcaption>Credits: <a href="https://developer.apple.com/videos/play/wwdc2019/402/">WWDC 2019</a></figcaption></figure><p>But, I was looking for more, how compiler actually does that. So, I dived into <a href="https://apple.github.io/swift-evolution/">Swift Evolution Github Page</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zw50xTKRW5eZBO_iZE8IDA.jpeg" /><figcaption>Swift Evolution Github Page, Credits: <a href="https://developer.apple.com/videos/play/wwdc2019/402/">WWDC 2019</a></figcaption></figure><p>and found the <a href="https://github.com/apple/swift-evolution/blob/9992cf3c11c2d5e0ea20bee98657d93902d5b174/proposals/XXXX-function-builders.md">Initial Draft of the Function Builders</a> proposal &amp; the corresponding <a href="https://github.com/apple/swift/pull/25221">PR</a>. But, sadly most of the code was compiler level which I don’t understand. If you do, then it’s definitely a gold mine. <br>But I did find <a href="https://github.com/apple/swift/pull/25221/files#diff-cbf1044dbb8b4fa52c20c4420acc89a1b20a5e2fc3d2fdb9adc792c8fb6100a6">function_builder.swift</a> which creates a function builder for <em>Tuple</em> which I had seen earlier on the documentation when I was working on SwiftUI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qHNP6AwqF_n6fruKjl6UNg.png" /><figcaption>Courtesy: <a href="https://github.com/apple/swift/pull/25221">Function Builder Pull Request</a></figcaption></figure><p>So, now I was left with only two options: SwiftUI <a href="https://developer.apple.com/documentation/swiftui/">Documentation</a> &amp; <a href="https://developer.apple.com/tutorials/swiftui/creating-and-combining-views">Tutorial</a> which uses the power of Function Builders extensively. Even though Tutorial is great, it doesn’t talk about how it works behind the scenes. And the Documentation was overwhelming.</p><p>So, I decided to try my hands on it on Playground &amp; follow along with the documentation, as an Odiya (the native language of <a href="https://en.wikipedia.org/wiki/Odisha">Odisha</a>, an Indian State) saying goes:</p><blockquote>Nije namale, jama darshana nahin<br>(which loosely translates to: “One won’t get to see <a href="https://en.wikipedia.org/wiki/Yama_(Hinduism)">Yama</a> (the lord of death and justice) until own death”)</blockquote><p><strong>Side Note: </strong>You can Access documentation without a network connection, <em>Xcode -&gt; Help -&gt; Developer Documentation</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*4MthRnKBQMVTUQQo9NG-Dg.png" /></figure><p>Looking at the Documentation of View, I tried to recreate <strong>View</strong> (basic building block of SwiftUI Views) <strong>Protocol</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d86299bab554e0820fb7dbeb8abe0083/href">https://medium.com/media/d86299bab554e0820fb7dbeb8abe0083/href</a></iframe><p>Here comes <a href="https://developer.apple.com/documentation/swiftui/viewbuilder">ViewBuilder</a> into the picture, which is a Function Builder for SwiftUI Views.</p><p>Documentation of ViewBuilder was a little too much for me. So, before writing the pseudo-code, I wanted to check if it’s real &amp; if possible gather some extra information from Playground:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/761a84b46adaf65932435accefe92ba1/href">https://medium.com/media/761a84b46adaf65932435accefe92ba1/href</a></iframe><p>From this simple experiment, I gathered a few extra information:</p><ul><li>VStack takes a single closure, which is pretty similar to any other swift closure.</li><li>If we don’t provide any view to it, it takes the form of an <strong>EmptyView</strong>.</li><li>If we provide a single view to it, it takes the form of that <strong>View</strong> (in our case Text)</li><li>If we provide multiple views to it, it takes the form of a <strong>TupleView</strong> &amp; stores the views in its <em>value</em>.</li><li>VStack stores things in a <em>tree</em> of type <strong>VariadicView.Tree </strong>with self as the <em>root</em> and the final form of closure containing the views as it’s <em>content</em>. This is probably the reason how SwiftUI can apply a modifier (say background color) from parent to all of its children.</li></ul><p>With that in mind, I tried filling pseudo-code for ViewBuilder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1042535a4966d4183056a54aec7c7c83/href">https://medium.com/media/1042535a4966d4183056a54aec7c7c83/href</a></iframe><p>With that in place, I wanted to repeat the same experiment I did for SwiftUI VStack, but this time with our VStackAlias &amp; our implementation of EmptyView &amp; TupleView:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8faf845ce58f22889758576b3d69315/href">https://medium.com/media/a8faf845ce58f22889758576b3d69315/href</a></iframe><p>and wait for it… the results were pretty similar. Now, I couldn’t agree more with the findings of the SwiftUI playground experiment I did earlier:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jf62pr0kSF4SkYJCpOQulw.png" /><figcaption>Function Builder Mapping</figcaption></figure><p>Based on the number of views passed to the closure &amp; their type, the compiler smartly synthesizes code to correctly map the closure to the right build block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fuvcdnjyU8Gb4KL6NJonBg.png" /><figcaption>Function Builder compiler code synthesis</figcaption></figure><p>So basically, each of the views passed to the <em>VStackAlias</em> closure is effectively an expression synthesized by the compiler behind the hood. <br>And all this is possible because of the special custom attribute <strong><em>@_functionBuilder</em></strong><em> </em>which tells the compiler to auto-synthesize the closure block by looking at the definition of different build blocks in the Function Builder.</p><p>Now that I had a fair bit of idea, I wanted to implement a few use-cases of Function Builder.</p><p>But before that, here is an excerpt for you from the <a href="https://github.com/apple/swift-evolution/blob/9992cf3c11c2d5e0ea20bee98657d93902d5b174/proposals/XXXX-function-builders.md#function-building-methods">function-builder methods</a> currently proposed:<br>In the following descriptions, Expression stands for any type that is acceptable for an expression-statement to have (that is, a raw partial result), Component stands for any type that is acceptable for a partial or combined result to have, and Return stands for any type that is acceptable to be ultimately returned by the transformed function.</p><ul><li>buildExpression(_ expression: Expression) -&gt; Component is used to lift the results of expression-statements into the Component internal currency type. It is only necessary if the DSL wants to either (1) distinguish Expression types from Component types or (2) provide contextual type information for statement-expressions.</li><li>buildBlock(_ components: Component...) -&gt; Component is used to build combined results for most statement blocks.</li><li>buildFunction(_ components: Component...) -&gt; Return is used to build combined results for top-level function bodies. It is only necessary if the DSL wants to distinguish Component types from Return types, e.g. if it wants builders to internally traffic in some type that it doesn&#39;t really want to expose to clients. If it isn&#39;t declared, buildBlock will be used instead.</li><li>buildDo(_ components: Component...) -&gt; Component is used to build combined results for do statement bodies, if special treatment is wanted for them. If it isn&#39;t declared, buildBlock will be used instead.</li><li>buildOptional(_ component: Component?) -&gt; Component is used to build a partial result in an enclosing block from the result of an optionally-executed sub-block. If it isn&#39;t declared, optionally-executed sub-blocks are ill-formed.</li><li>buildEither(first: Component) -&gt; Component and buildEither(second: Component) -&gt; Component are used to build partial results in an enclosing block from the result of either of two (or more, via a tree) optionally-executed sub-blocks. If they aren&#39;t both declared, the alternatives will instead be flattened and handled with buildOptional; the either-tree approach may be preferable for some DSLs.</li></ul><h3>Examples:</h3><h4>1. Array:</h4><p>I thought I would start small, something as trivial as an Array.</p><p>So basically, I wanted to check if I can write [7, 8, 6] as something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f65daf076ca403120eb5486fdceacbc/href">https://medium.com/media/1f65daf076ca403120eb5486fdceacbc/href</a></iframe><p>This might look silly to try, but trust me it helped my understanding for the better examples. Okay, Let’s see how I achieved this step by step by a Function Builder.</p><p>I started with the <em>buildBlock </em>for the combined result from the partial results:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02157074c679b27cb041ab4c163517fc/href">https://medium.com/media/02157074c679b27cb041ab4c163517fc/href</a></iframe><p>Next, extended an <em>init </em>on Array to use the ArrayBuilder we just created:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa1a772a203c76e241e0dddeaceb1748/href">https://medium.com/media/fa1a772a203c76e241e0dddeaceb1748/href</a></iframe><p>That’s it, now we can initialize an Array using the new ArrayBuilder &amp; this is how it looks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b7d8bbfed04dcac4927c0a07a0ba3f0/href">https://medium.com/media/1b7d8bbfed04dcac4927c0a07a0ba3f0/href</a></iframe><p>Let’s talk about the <em>intArray </em>(same goes for stringArray), the Swift compiler does the following steps:</p><p><em>// 1 (as marked on the code)<br></em>sees the first value <strong>7</strong> in the closure, stores it in a <em>var a</em></p><p><em>// 2<br></em>sees the second value <strong>8</strong> in the closure, stores it in a <em>var b</em></p><p><em>// 3</em><br>sees the third value <strong>6</strong> in the closure, stores it in a <em>var c</em></p><p><em>// 4</em><br>invokes build block<em> </em>with a, b &amp; c like this: <em>ArrayBuilder.buildBlock(a, b, c)</em></p><p>Then we pass the compiler synthesized closure from (4) to the <em>init</em> of Array; upon executing the closure, it returns [a, b, c] or [7, 8, 6]; which is then assigned to <em>self</em>.</p><p>Not tricky at all, right! 🤡<br>You are awesome 😎, let’s look at something better now.</p><h4>2. NSAttributedString</h4><p>First Let’s see how we used to write for Attributed Strings:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab0e12dd5db26af19ce35bcec584f987/href">https://medium.com/media/ab0e12dd5db26af19ce35bcec584f987/href</a></iframe><p>This will give us the below output on Playground’s Live View:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*x0sweaUZEuvG6g6GolNung.png" /></figure><p>This is good, but my final goal was much better:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3fc62faff600d0d817cc5379aae9bb7/href">https://medium.com/media/c3fc62faff600d0d817cc5379aae9bb7/href</a></iframe><p>I started with the <em>buildBlock </em>for the combined result from the partial results:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df4980ec2ba89a4e24414f1d9392e44c/href">https://medium.com/media/df4980ec2ba89a4e24414f1d9392e44c/href</a></iframe><p>Next, added <em>buildExpression </em>for what types of expressions the builder supports. In our example, we will accept strings, and lift them to attributed substrings:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b32ddb21e71846784c8debc69c226f0/href">https://medium.com/media/7b32ddb21e71846784c8debc69c226f0/href</a></iframe><p>Next, added support for modifying attributes with an <em>extension</em> on NSAttributedString:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdef42ba3d6971e596887b305835fbda/href">https://medium.com/media/cdef42ba3d6971e596887b305835fbda/href</a></iframe><p>Last, but best, added a <em>convenience init </em>on NSAttributedString to use the AttributedStringBuilder we just created:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a5a4ef097e9867465d929f0fa3434f1/href">https://medium.com/media/4a5a4ef097e9867465d929f0fa3434f1/href</a></iframe><p>That’s it, now I can initialize NSAttributedString using the new AttributedStringBuilder &amp; this is how it looks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a68f30a7fdee650ac2c973ade8d01bb0/href">https://medium.com/media/a68f30a7fdee650ac2c973ade8d01bb0/href</a></iframe><p>The Swift compiler translates the above code into the following AttributedStringBuilder method calls:</p><ol><li>buildExpression() with the NSAttributedString argument.</li><li>buildExpression() with the String argument.</li><li>After all partial results have been built, the method buildBlock() is invoked with all intermediate NSAttributedStrings as arguments.</li></ol><p>Executing the Playground, gave us the same output as before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*x0sweaUZEuvG6g6GolNung.png" /></figure><h4>3. AlertViewController:</h4><p>First Let’s see how we used to write for AlertViewController:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af5081d9c3e7ee2e59aa644e61e505ee/href">https://medium.com/media/af5081d9c3e7ee2e59aa644e61e505ee/href</a></iframe><p>This will give us the below output on Playground’s Live View:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*nMQK71vniwUQYkGYzaVZ9w.png" /></figure><p>This is good, but using a function builder approach (like we did in the previous example for NSAttributedString) is much better:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d90eaf398cecd9a38556983356601b1d/href">https://medium.com/media/d90eaf398cecd9a38556983356601b1d/href</a></iframe><h4>4. UIStackView:</h4><p>We won’t be seeing how we used to write it as we all know, use &amp; love StackView.<br>So, let’s directly jump onto the Function Builder implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73cc979ffaa8f323473abc564eba714e/href">https://medium.com/media/73cc979ffaa8f323473abc564eba714e/href</a></iframe><p>This gives us the below output on Live View:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*bvpCq0HPoy_-9RecWtH39g.png" /></figure><p>Even though this example is pretty small, it’s good enough to demonstrate how the function builder approach embraces the in-place context &amp; the truly hierarchical nature of StackView.</p><p><strong>4. HTML DSL:<br></strong>This is something I am currently working on. It’s a rather extensive example, if you have a fair bit of idea on SwiftUI &amp; Function Builder (I hope you will have now 😛), do check out the code on <a href="https://github.com/shahrukhalam/HTMLDSL">Github</a>.</p><h3>Conclusion:</h3><p>In this article, we discussed Function Builder in length. How Apple has brought the power of Swift &amp; DSL together.</p><p>I think Swift as a language is getting more &amp; more powerful, elegant &amp; easy to use. We have the right amount of tools to create something beautiful not only on DSL but also on the Server-Side. Now, it’s on us, the developers to take it forward to a completely different level.</p><p>I hope you enjoyed the article &amp; learned behind the scenes of Function Builders. Do check out the complete playground on <a href="https://github.com/shahrukhalam/Decoding-Function-Builder">Github</a>.</p><p>Happy Coding &amp; Sharing 😍<br>Cheers 🍺<br><a href="https://www.linkedin.com/in/alamshahrukh/">Shahrukh Alam</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be21e9f13429" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift-india/how-i-decoded-function-builders-in-swift-be21e9f13429">How I Decoded Function Builders in Swift</a> was originally published in <a href="https://medium.com/swift-india">Swift India</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure Secrets in iOS app]]></title>
            <link>https://medium.com/swift-india/secure-secrets-in-ios-app-9f66085800b4?source=rss-4560785bf7b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f66085800b4</guid>
            <category><![CDATA[xcconfig]]></category>
            <category><![CDATA[secrets]]></category>
            <category><![CDATA[cocoapods]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Shahrukh Alam]]></dc:creator>
            <pubDate>Fri, 13 Nov 2020 16:53:05 GMT</pubDate>
            <atom:updated>2020-11-13T16:53:05.696Z</atom:updated>
            <content:encoded><![CDATA[<p>How do we store our secrets on the client-side? Are we really vulnerable to attacks? Is it really worthwhile to take the measures to store them securely?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IsuuvAMwC8S9iSB_.jpeg" /><figcaption>Courtesy: <a href="https://medium.com/a-crack-in-the-fourth-wall/ideas-are-bulletproof-and-dangerous-1df1bca46bce">Ideas are Bulletproof and Dangerous</a></figcaption></figure><p>Almost all the iOS apps have some secret keys to protect like:</p><ul><li>API keys</li><li>Private Headers</li><li>Cryptographic Keys</li><li>Passwords</li></ul><p>These keys are needed:</p><ul><li>to set up third-party SDKs</li><li>to authenticate with backend APIs</li><li>to automate build process or to use in any developer tools, such as communicating to Apple Developer Account or App Store Connect</li></ul><p>But imagine a situation, where they are compromised, for instance, if someone gets hold of our Firebase API key, now he/she can easily misuse or overuse our paid credentials if he/she is determined &amp; skilled to hack into few other related keys.</p><p><strong>Q:</strong> Are our keys really this vulnerable to attacks?</p><p><strong>A:</strong> Yes &amp; No<br><strong><em>Yes:</em></strong> If we hardcode them in the source code or if we push them on the source control.<br><strong><em>No:</em></strong> If we take some basic measures to secure them, also it takes little determination and a lot of skills from a hacker to extract or debug them from the binary.</p><p><strong>Q:</strong> Is it really worthwhile to take the measures to store them securely?</p><p><strong>A:</strong> Yes &amp; No<br><strong><em>Yes: </em></strong>Because they are our App Secrets</p><blockquote>If you would keep your secret from an enemy, tell it not to a friend.<br>- Benjamin Franklin from <a href="https://nshipster.com/secrets/">NSHipster</a></blockquote><p><strong><em>No:</em></strong> Because we can’t make it 100% hack-free</p><blockquote>Be aware you should authenticate <em>users</em>, not authenticate an <em>app</em>. It’s mathematically impossible to hide data perfectly yet still be able to access it from your code.<br>- Chris Hulbert from <a href="https://www.splinter.com.au/2019/05/05/obfuscating-keys/">Splinter</a></blockquote><blockquote>The only way to keep a secret is to never have one.<br>- Julian Assange from <a href="https://nshipster.com/secrets/">NSHipster</a></blockquote><h3>How do we store our secrets on the client-side?</h3><p>There are various ways to do it, it’s covered beautifully in this <a href="https://nshipster.com/secrets/">NSHipster Article</a> by <a href="https://twitter.com/mattt"><em>Mattt</em></a>. The most effective one is <strong>Obfuscating</strong> which is discussed in length by <a href="https://www.linkedin.com/pub/chris-hulbert/1a/276/503"><em>Chris Hulbert</em></a> <a href="https://www.splinter.com.au/2019/05/05/obfuscating-keys/">here</a> &amp; <a href="https://www.splinter.com.au/2014/09/16/storing-secret-keys/">here</a>.</p><p>We are going to discuss the easiest, yet quite effective Apple’s way, by using Xcode Configurations and Info.plist.</p><p><strong>Step 1:</strong></p><p>We start with an <em>initial commit</em> to <a href="https://github.com/shahrukhalam/SecureAPIKeys">SecureAPIKeys</a> Project.</p><p><strong>Step 2:</strong></p><p>We add a New Config<em> </em>File<em> </em>in the Project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_uugzqaSz4OPP9pWZ3tseg.png" /></figure><p><strong>Step 3:</strong></p><p>Please make sure you <strong>don’t</strong> check any Targets which is also the default in Xcode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xpvt3BxnAJzd69BFObzI9Q.png" /></figure><p><strong>Step 4:</strong></p><p>Let’s add an API Key in the Config.xcconfig</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SiwRLfFQevf2fB7SJfWX2A.png" /></figure><p><strong>Step 5:</strong></p><p>Add Config.xcconfig to the <em>gitignore</em>. This step is very important as we don’t want it to be available to everyone who has access to our repo.<br>If due to some reason our repo is compromised, the hacker won’t get hold of our secrets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5sQUx3G-yiX_4MjBvhW2nQ.png" /></figure><p><strong>Step 6:</strong></p><p>Let’s add the API Key to our info.plist. The <em>API_KEY </em>in our Config.xcconfig acts as a User-defined Variable which can be accessed by <em>$(API_KEY) </em>on the info.plist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2f9LZpXsnVKWUkHdm0T-Pw.png" /></figure><p><strong>Step 7:</strong></p><p>Let’s set the Config.xcconfig to the Configurations to our App Project. <br>You can always create different xcconfigs for Debug &amp; Release, for simplicity of this article we will keep one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nm1lc3ZWfBlyX7bn_GSWPQ.png" /></figure><p><strong>Step 8:</strong></p><p>Let’s do a simple check if we can access our API Key in the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNTjq1Ig7n5pye6_rIo6LQ.png" /></figure><p>Now let’s build &amp; run for both Debug &amp; Release, it should look something like this in both:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kRKgV_bGcaKm-v3Ye2nkLA.png" /></figure><h3>Validation:</h3><p>Let’s add a hardcoded API Key just to see how it can be hacked but the API Key from xcconfig might not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ok0164QZbHSc7gZtKhKzWQ.png" /></figure><p>Now let’s create an Archive. Find the Archive by <em>Show in Finder</em> from Organiser. Go to App Executable folder by <em>Show Package Contents</em> on the Archive -&gt; Products -&gt; Applications. Find the App Binary by <em>Show Package Contents</em> on App Executable. It will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BT9fGGxuUC37D8o3s2zpUQ.png" /></figure><p><em>cd</em> to this folder in Terminal &amp; run <strong><em>strings</em></strong> command on the App Binary. You can find HARDCODED_API_KEY, but not API_KEY from xcconfig. <br>There are many tools like <a href="http://www.suavetech.com/0xed/">hex editor</a> or <a href="https://sourceforge.net/projects/machoview/">MachOView</a> out there which makes this hack &amp; peek really easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94MdmiHdFnxsZ8eyAIW8rw.png" /></figure><p>Now the question might come, where is our API_KEY from the xcconfig? It’s sitting on the info.plist in App Executable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kN9EyvSxS5UDBhHPPYoLow.png" /></figure><p>If you would open it, you can find the API_KEY with its value exposed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dr6YW9U_YLlPpfieTqqenA.png" /></figure><p>Here, someone might argue that it’s easily hackable, may be easier than our HARDCODED_API_KEY. But, I believe if someone has an access to our Archive, then he/she is an inside man/woman who already knows the value and he/she is the one who created it in the first place.</p><p>Now, let’s talk about a hacker, an outsider. He/She can hack into our repo or the App Binary. In either case, he/she won’t get to know about our Config.xcconfig from the repo or the API_KEY from the App Binary.</p><p>Now, let’s talk about a rare, but a critical scenario where the hacker gets the entire code from an employee’s machine. In this situation, most of the methods would fail including the one we discussed.</p><p>If you have gone through the <a href="https://nshipster.com/secrets/">NSHipster</a> article, let’s go through how all the methods might fail:</p><ul><li><strong>Hard-Code Secrets in Source Code:</strong> This is too easy.</li><li><strong>Xcode Configuration and Info.plist:</strong> This is also very easy as the hacker can find the Config.xcconfig given to the employee secretly/separately for the project to work.</li><li><strong>Obfuscate:</strong> The hacker would know the <strong>Salt </strong>used to encode or decode the keys.</li><li><a href="https://github.com/orta/cocoapods-keys"><strong>Cocoapod-Keys</strong></a><strong>: </strong>Key names are in the Podfile. The generated Objective-C classes are stored in the Pods/CocoaPodsKeys directory. Someone skillful can easily break the scrambled versions of the keys.</li></ul><p>The only ways left are:</p><ul><li><strong>Don’t Store Secrets On-Device:</strong> Store them on your own Server or iCloud. Once a secure connection is made, store them in the client’s <a href="https://developer.apple.com/documentation/security/certificate_key_and_trust_services/keys/storing_keys_in_the_secure_enclave"><em>Secure Enclave</em></a><em> </em>like Keychain. But, is it worth it?</li></ul><blockquote>A secret in Secure Enclave is safe, but that is not what secrets are for.<br>- <a href="https://twitter.com/mattt">Mattt</a> from <a href="https://nshipster.com/secrets/">NSHipster</a></blockquote><ul><li><strong>Don’t Store Secrets at all: </strong>It’s the most difficult, but the best way to go about the secret keys.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SQA8cgyzdhsTdAzSftSA8g.jpeg" /><figcaption>Courtesy: <a href="https://quotefancy.com/quote/15281/Bob-Dylan-When-you-got-nothing-you-got-nothing-to-lose">Bob Dylan</a></figcaption></figure><h3>Conclusion:</h3><p>Try to avoid using Secret Keys wherever possible. If not, try adding some measures to hide them from attackers. <br>Use Secure Network Connections like Transport Layer Security (TSL) by using Apple’s Network Framework or App Transport Security of URLSession as explained in the <a href="https://developer.apple.com/videos/play/wwdc2019/709/">WWDC Video 2019</a> (13:00).<br>Use <a href="https://www.raywenderlich.com/1484288-preventing-man-in-the-middle-attacks-in-ios-with-ssl-pinning">SSL Certificate Pinning</a> to stay safe from Bots, Proxies, or Man-in-the-Middle Attacks.</p><p>You could find the full code on Github: <a href="https://github.com/shahrukhalam/SecureAPIKeys">SecureAPIKeys</a></p><p>Happy Coding &amp; Sharing 😍<br>Cheers 🍺<br><a href="https://www.linkedin.com/in/alamshahrukh/">Shahrukh Alam</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f66085800b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift-india/secure-secrets-in-ios-app-9f66085800b4">Secure Secrets in iOS app</a> was originally published in <a href="https://medium.com/swift-india">Swift India</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Static Library in iOS]]></title>
            <link>https://medium.com/swift-india/static-library-in-ios-d133123678d1?source=rss-4560785bf7b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d133123678d1</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[static-library]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Shahrukh Alam]]></dc:creator>
            <pubDate>Sat, 07 Nov 2020 11:57:32 GMT</pubDate>
            <atom:updated>2024-01-07T08:33:56.129Z</atom:updated>
            <content:encoded><![CDATA[<h4>Are you Duplicating a piece of code for a particular functionality across multiple Apps? Do you find it difficult to fix a bug on all those places? If Yes, then Static Library is an answer to our problems.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*FNzGIdEI8wEbmVBpZASuEg.jpeg" /><figcaption>Courtesy: <a href="https://www.instagram.com/tidecharmers/">Tide Chambers</a></figcaption></figure><blockquote>this article has been moved <a href="https://unknowndefault.com/static-library-in-ios">here</a> 😍</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d133123678d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift-india/static-library-in-ios-d133123678d1">Static Library in iOS</a> was originally published in <a href="https://medium.com/swift-india">Swift India</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Face ID/Touch ID in iOS]]></title>
            <link>https://medium.com/swift2go/integrating-face-id-touch-id-in-ios-78da7080f742?source=rss-4560785bf7b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/78da7080f742</guid>
            <category><![CDATA[face-id]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[touch-id]]></category>
            <dc:creator><![CDATA[Shahrukh Alam]]></dc:creator>
            <pubDate>Sun, 02 Aug 2020 19:42:42 GMT</pubDate>
            <atom:updated>2020-12-09T10:34:15.350Z</atom:updated>
            <content:encoded><![CDATA[<p>Did you know Facial Recognition dates back to <a href="https://www.facefirst.com/blog/brief-history-of-face-recognition-software/">1960s</a> with manual measurements of facial coordinates. It’s used by govt agencies like DOJ, FBI, DEA, CBP and U.S. Marshalls. In-fact US-Govt used facial recognition to confirm the identity of Osama bin Laden for Operation Neptune Spear in 2011.</p><p>But with the introduction of Face-ID in iPhone X, Apple changed history. Now, iPhone X can analyse 30,000 facial dots in just 1 S (30% improvement in iPhone 11) with 1 error in 1 M (obviously excluding Twins 😍 😍). And now it’s coming with Masks on in iOS 13.5, thanks to the pandemic 😢 😢.</p><h3>Maker ➡️ Fan-Boy ➡️ Reader :</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F56QZweGjih4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D56QZweGjih4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F56QZweGjih4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/16f9eb1fcf1515220c8f8ec2634f7e1b/href">https://medium.com/media/16f9eb1fcf1515220c8f8ec2634f7e1b/href</a></iframe><h3>Enough of Past &amp; Present, Let’s dive into Future :</h3><p>Let’s implement. When it comes to the authentication mechanisms, Apple’s baby is <strong>LocalAuthentication</strong> framework. It has 3 main components:</p><p><a href="https://developer.apple.com/documentation/localauthentication/lacontext"><strong>LAContext</strong></a><strong> </strong>: An authentication context object is used to evaluate the user’s identity, either with biometrics like Touch ID or Face ID, or by supplying the device passcode.</p><p><a href="https://developer.apple.com/documentation/localauthentication/lacontext/1514149-canevaluatepolicy"><strong>canEvaluatePolicy</strong></a><strong> </strong>: An API called on context to determine if a particular <a href="https://developer.apple.com/documentation/localauthentication/lapolicy">policy</a> can be evaluated. Returns <em>true</em> if the policy can be evaluated, otherwise <em>false</em>.</p><ul><li>Policy basically decides if you need just Face ID/Touch ID or both Face ID/Touch ID &amp; Device Passcode. In our case we will use prior, <em>deviceOwnerAuthenticationWithBiometrics </em>(recommended, by Apple)</li><li>It also takes a NSError Pointer to return back the <a href="https://developer.apple.com/documentation/localauthentication/laerror/code">LAError Code</a> in case it can’t evaluate the policy.</li><li>After getting a Success/Failure, we can know about <a href="https://developer.apple.com/documentation/localauthentication/labiometrytype">LABiometryType</a>, if the current device supports Face-ID/Touch-ID or none.</li></ul><p><a href="https://developer.apple.com/documentation/localauthentication/lacontext/1514176-evaluatepolicy"><strong>evaluatePolicy</strong></a> : An API called on context after a success from <em>canEvaluatePolicy</em>. It begins authenticating Face-ID with animating HUD.</p><ul><li>It’s asynchronous</li><li>It takes a policy to evaluate, and a <em>localizedReason </em>(will see later in here) for it.</li><li>Returns a closer with Success/Failure &amp; an Error if any with <em>LAError Code</em>.</li></ul><h3>Now, Let’s go with the Flow :</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*-mzI1794AcTxt9bdb72bEw.png" /></figure><h3>Wrapper makes it Better :</h3><ul><li>Let’s create a wrapper file named BiometricIDAuth.swift.</li><li>Import LocalAuthentication</li><li>Advantage of having a wrapper is that, we don’t need to keep importing the dependencies everywhere else in the App, where it’s used by the clients.</li><li>Let’s add the <strong>LAContext</strong> &amp; <strong>LAPolicy</strong> properties discussed earlier.</li><li>Now, we will add few properties like <em>localizedReason</em>, <em>localizedFallbackTitle </em>&amp; <em>localizedCancelTitle</em> needed for customising the context.</li><li>We will also keep a <strong>NSError?</strong> property that will be sent to <em>canEvaluatePolicy</em> as a pointer as discussed earlier.</li></ul><p>Our BiometricIDAuth.swift will now look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c67e460743995a04f064d71863b54320/href">https://medium.com/media/c67e460743995a04f064d71863b54320/href</a></iframe><ul><li>Next, let’s add two enums:</li></ul><p><strong>BiometricType</strong>, will map <em>LABiometryType</em> of our <em>LAContext</em></p><p><strong>BiometricError</strong>, will map <em>NSError </em>returned from <em>canEvaluatePolicy </em>&amp; <em>evaluatePolicy</em>. It confirms to <strong>LocalizedError </strong>that will help us with displaying proper error messages to User.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d3401c78f7b452b0b51246135a8a435/href">https://medium.com/media/5d3401c78f7b452b0b51246135a8a435/href</a></iframe><ul><li>Next, let’s add the methods that will actually do this mapping</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db7ef19f2b0e0f9b64f2dd7a879e40c2/href">https://medium.com/media/db7ef19f2b0e0f9b64f2dd7a879e40c2/href</a></iframe><ul><li>Next, let’s add the two main functions which we have been waiting for, which will do the magic for our Face-ID/Touch ID authentication.</li></ul><ol><li>Starting with <em>canEvaluatePolicy</em> :</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19adcf3acad62adb26755aeda1f78616/href">https://medium.com/media/19adcf3acad62adb26755aeda1f78616/href</a></iframe><p>2. And then, <em>evaluatePolicy</em> :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20ba881df2872d03da2c458c715e4a7e/href">https://medium.com/media/20ba881df2872d03da2c458c715e4a7e/href</a></iframe><h3>Think globally, Act locally :</h3><p>Now, let’s understand what all those <em>localizedReason</em>, <em>localizedFallbackTitle </em>&amp; <em>localizedCancelTitle</em> needed for customising the context are, by recalling the failure popups from the earlier Flow Chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*jnAUaChEpjdqO2VLY7kBcg.png" /></figure><h3>Join the Dots :</h3><p>Let’s bring the wrapper into use.</p><ul><li>Create AuthenticationViewController.swift</li><li>Add a property for <strong>BiometricIDAuth</strong></li></ul><pre>private let biometricIDAuth = BiometricIDAuth()</pre><ul><li>Create an <em>IBAction </em>for “verify with Face ID” button and put the below code in :</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fda866f90792555aa857d1f9548ff4c6/href">https://medium.com/media/fda866f90792555aa857d1f9548ff4c6/href</a></iframe><h3>Last, but not the least :</h3><p>For Face ID, We have to include the <a href="https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW75">NSFaceIDUsageDescription</a> (Privacy Face ID Usage Description) key in our app’s Info.plist file. Without this key, the system won’t allow our app to use Face ID.</p><p>If your app needs to use just Touch ID, you don’t need to do above step. (Just Kidding, there will be no such case 😂😂)</p><h3>Demo Time 🚀🚀:</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FgkXUpIWrVpE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgkXUpIWrVpE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgkXUpIWrVpE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/50291241f614dad5783805e954d90d17/href">https://medium.com/media/50291241f614dad5783805e954d90d17/href</a></iframe><h4>What if I don’t have a Device 😎</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-t-Ikg7CbSI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-t-Ikg7CbSI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-t-Ikg7CbSI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d453ce62579b40c6b5219bdaa50942c/href">https://medium.com/media/3d453ce62579b40c6b5219bdaa50942c/href</a></iframe><h3>Well guess what, we’re Done :</h3><p>I feel Face-ID/Touch-ID is a seamless way to onboard users and access sensitive information leveraging Apple’s Secure Enclave. It’s a great feature to have on Modern Apps.</p><p>Checkout the complete code at <a href="https://github.com/shahrukhalam/FaceIDAuthentication">Github Repo</a>.</p><p>Find me on <a href="https://github.com/shahrukhalam">Github</a> &amp; <a href="https://www.linkedin.com/in/alamshahrukh/">Linkedin</a>. If you liked the article, hit the 👏 button. If you didn’t, please put your suggestion for improvement on comments. Do check the great references below for more information.</p><h3>References :</h3><p><a href="https://www.raywenderlich.com/236-how-to-secure-ios-user-data-the-keychain-and-biometrics-face-id-or-touch-id">Raywenderlich</a></p><p><a href="https://www.hackingwithswift.com/read/28/4/touch-to-activate-touch-id-face-id-and-localauthentication">Hackingwithswift</a></p><p><a href="https://developer.apple.com/documentation/localauthentication/logging_a_user_into_your_app_with_face_id_or_touch_id">Apple Doc for implementation</a></p><p><a href="https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/authentication/">Apple Human Interface Guidelines</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78da7080f742" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift2go/integrating-face-id-touch-id-in-ios-78da7080f742">Integrating Face ID/Touch ID in iOS</a> was originally published in <a href="https://medium.com/swift2go">Swift2Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>