<?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 Dmitriy Ignatyev on Medium]]></title>
        <description><![CDATA[Stories by Dmitriy Ignatyev on Medium]]></description>
        <link>https://medium.com/@dy.ignatyev?source=rss-83f7767d105e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*qJ_cbt3q-s_UR0NV4g1nxg.jpeg</url>
            <title>Stories by Dmitriy Ignatyev on Medium</title>
            <link>https://medium.com/@dy.ignatyev?source=rss-83f7767d105e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 10:37:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dy.ignatyev/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[Combine, Ready for Swift 6 strict concurrency]]></title>
            <link>https://medium.com/@dy.ignatyev/combine-ready-for-swift-6-5b7a471a1c55?source=rss-83f7767d105e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b7a471a1c55</guid>
            <dc:creator><![CDATA[Dmitriy Ignatyev]]></dc:creator>
            <pubDate>Wed, 05 Aug 2026 15:44:58 GMT</pubDate>
            <atom:updated>2026-08-05T16:05:44.213Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-4ge82YNSK9jfMs0fjm4lA.jpeg" /></figure><p>Swift 6’s strict concurrency checking is one of the best things to happen to Apple’s platforms in years — and one of the most disruptive, if your codebase is built on Combine.</p><p>Combine was designed before Swift had actors, @Sendable, or the vocabulary we now use to talk about concurrency. That isn&#39;t a flaw in its engine – Combine has real thread-safety built in. It&#39;s a flaw in its labels. In Swift 6, if a type doesn&#39;t say Sendable, the compiler assumes the worst. Combine&#39;s types say nothing.</p><p>Take the most innocent code in the world:</p><pre>let subject = PassthroughSubject&lt;Int, Never&gt;()</pre><pre>Task { @MainActor in<br>  subject.send(1)<br>}</pre><p>In Swift 6’s strict mode, this does not compile. The error is the shape of most Combine migrations: a non-Sendable value – the subject – captured in a @Sendable closure. The subject crossed isolation boundary, and the compiler stopped it before the code ever ran.</p><p>That’s wall number one: the types. Here’s wall number two, the one people notice later. Combine’s operators take closures that are not @Sendable:</p><pre>final class Counter {<br>  var count = 0<br>}</pre><pre>let counter = Counter()               // not Sendable – shared mutable state</pre><pre>// Values are sent from a background thread...<br>DispatchQueue.global().async {<br>  counter.count += 1<br>}</pre><pre>subject.map { value in<br>  counter.count += value            // mutation on another thread<br>  return counter.count<br>}</pre><pre>// The main thread mutates the same object:<br>counter.count += 1</pre><p>This compiles — and that’s the problem. Nothing checks what the closure captured, because the closure was never marked @Sendable. Combine runs that closure on whatever thread delivers the value. If it&#39;s a background thread, and the closure touches formatter or any other non-Sendable state, you can have a data race that the compiler allows. The build is green; the crash is later.</p><p>So the gap has two faces: Combine’s types don’t carry the Sendable label, and its operator closures don&#39;t require it. Both let unsafe code compile.</p><p>Every workaround costs more than it seems.</p><p>@preconcurrency import Combine turns the diagnostics off for the entire module. The exact checks you adopted Swift 6 to get are gone, invisibly, project-wide.</p><p>AsyncStream avoids the problem by leaving Combine behind: its operators, its backpressure, its cancellation – and the pipeline code you already wrote, which now has to be rewritten from scratch.</p><p>And the unofficial standard: a hand-written @unchecked Sendable wrapper, reimplemented in every project that hits this wall, with slightly different bugs each time. Here&#39;s the part people miss: that wrapper fixes only wall one. It makes the subject Sendable – and does nothing about your map { } and filter { } closures, which can still capture non-Sendable state, unchecked.</p><p>The real problem, stated plainly: Combine is safe but unlabeled. What’s missing is a type-level statement that a publisher may cross a concurrency boundary, and @Sendable closures so the compiler can check what a pipeline captures.</p><p>For these two problems, no rewrite is needed. Instead, a small library was written: <strong>SendablePublishers </strong>(<a href="https://github.com/iDmitriyy/SendablePublishers">https://github.com/iDmitriyy/SendablePublishers</a>), a thin layer on top of Combine. It is not heavy machinery — no new engine, no reimplemented operators, nothing to install into your build beyond one import. The moment you add it, the compiler starts doing the checking that Combine left undone. It does three small things, and together they close both walls.</p><p><strong>First, a type you can write in your signatures:</strong></p><pre>public typealias SendablePublisher&lt;Output: Sendable, Failure&gt; =<br>  Publisher&lt;Output, Failure&gt; &amp; Sendable</pre><p>let coordinates: AnySendablePublisher&lt;Coordinates, Never&gt; is a real Sendable type. The compiler enforces the rules for it – it can live in a struct and cross isolation boundaries – and the checking goes with it.</p><p><strong>Second, a wrapper — </strong><strong>SendableShell – that keeps the pipeline&#39;s exact type and wraps the whole operator surface:</strong></p><pre>let events = subject.asSendablePublisher()</pre><p>SendableShell holds the pipeline and declares itself Sendable. And here is the part that closes wall number two: the library redefines every standard operator – map, filter, flatMap, combineLatest, debounce, retry, and the rest – so each one takes a @Sendable closure. The chain stays Sendable end to end, and the compiler now checks what every closure captures. The class Counter code from earlier becomes a compile error at build time, instead of a race you debug later. No erasure, no runtime cost – the pipeline stays exactly as you wrote it.</p><p><strong>Third, a retroactive conformance for the two subjects everyone already uses:</strong></p><pre>extension PassthroughSubject: @retroactive @unchecked Sendable where Output: Sendable {}<br>extension CurrentValueSubject: @retroactive @unchecked Sendable where Output: Sendable {}</pre><p>@unchecked Sendable deserves an honest answer, because usually it&#39;s <strong>used to silence the compiler instead of fixing the problem.</strong>. Here it&#39;s the opposite. Combine&#39;s thread-safety lives behind internal locks the compiler can&#39;t inspect; this is trust in an implementation Apple already shipped, not an escape from a real problem. The @retroactive keyword makes the reach into Apple&#39;s types explicit. If Apple formalizes these conformances, two lines get deleted and nothing changes.</p><p>What does this buy in practice?</p><p><strong>No new mental model.</strong> This isn’t a new framework or a move to async sequences. It’s Combine, with a concurrency promise on top. Code reads the way Combine always did.</p><p><strong>Checks you can keep.</strong> Every operator closure is @Sendable; a mistake is a compile error at build time, not a data race you debug at 2 a.m.</p><p><strong>Boundaries that travel.</strong> A service owns a subject and hands out a Sendable view of it; a main-actor view model subscribes with no extra work. The crossing is now a checked, first-class thing.</p><p><strong>Change at your own pace.</strong> You don’t migrate a codebase in one weekend. Add the import, wrap the subject where it’s created, write Sendable signatures at the boundaries – the rest of the code stays as it is.</p><p><strong>Nothing to get wrong.</strong> The library reimplements nothing: no engine, no scheduler, no backpressure machinery. It compiles to about 68 KB of conformances and small forwarding functions. Fewer parts, fewer places to fail.</p><p><strong>It is not closed off.</strong> Libraries always miss a case, so instead of forking the whole library for a single use case there is an extension point: a small SPI interface that lets you <strong>make your own thread-safe publisher </strong><strong>Sendable</strong> and add your own operators with a plain extension. The entry point is deliberately named unverified_SendablePublisher – the honesty lives in that one word. The compiler can&#39;t check your claim, so the name reminds you that you did the reasoning, and that you should use it only when you can guarantee the publisher is safe.</p><p>Honest costs, because they exist. Concrete types stay concrete, so long chains produce long type names — that’s the price of zero-cost Sendability, and the reason erasure exists: AnySendablePublisher for a named type that fits stored properties, eraseToOpaque() when you only want to hide the type, with no extra cost. And the retroactive conformance is the library&#39;s only reach into Apple&#39;s types – explicit, and gone the day Apple ships its own.</p><p>What’s next: Driver/Signal traits whose sink always runs on the main thread, CancellationBag replacing Set&lt;AnyCancellable&gt; and living and dying with its owner, and a clean bridge to AsyncAlgorithms.</p><p>The takeaway: Swift 6 didn’t break Combine. It asked Combine to say what it’s safe to do, and Combine — a framework from before the concurrency era — lacked the words. The fix was never a rewrite, a move away, or a project-wide switch that turns the checks off. It was a label on something that was safe all along — on the types, and on the closures. Try it on one boundary in your codebase; the next Swift 6 migration will be shorter and easier.</p><p>SendablePublishers is free and open source on <a href="https://github.com/iDmitriyy/SendablePublishers">GitHub</a>, and installs with one line of Swift Package Manager:</p><pre>.package(url: &quot;https://github.com/iDmitriyy/SendablePublishers.git&quot;, from: &quot;0.1.0&quot;)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b7a471a1c55" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[XCode Asset Catalog: How to speed up project build by parallelizing Asset compilation]]></title>
            <link>https://medium.com/@dy.ignatyev/xcode-asset-catalog-how-to-speedup-and-parallelize-asset-compilation-c8d1d520a4da?source=rss-83f7767d105e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8d1d520a4da</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Dmitriy Ignatyev]]></dc:creator>
            <pubDate>Sun, 08 Mar 2026 18:57:37 GMT</pubDate>
            <atom:updated>2026-03-08T19:02:55.633Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-nZd5g2SKv8MZBnFhhYL6g.jpeg" /></figure><p>2026. Your laptop has 8–16 CPU cores. Apple Silicon chips are incredibly fast.</p><p>Swift compiles in parallel.</p><p>You press ⌘B — and one single core runs at 100% while the others sit idle.</p><p>Welcome to the world of <strong>single‑threaded Asset Catalog compilation</strong>.</p><p>In this article I’ll show <strong>why Asset Catalog can slow down your build and how to make Xcode use more CPU cores</strong>. Step by step, with examples.</p><p><strong>When resources start slowing down your project</strong></p><p>When a project has only a few assets, everything works fine. But once the project grows:</p><ul><li>hundreds of icons</li><li>dozens of colors</li><li>many illustrations</li></ul><p>resources can suddenly become a bottleneck and significantly increase build time.</p><p>In one of my previous projects, a build took about <strong>145 seconds</strong>.</p><p>Around <strong>75 seconds</strong> of that time was spent <strong>only on compiling assets</strong>.</p><p>Half of the total build time.</p><p>Just for images.</p><p>That’s clearly not ideal.</p><p>At that moment it became obvious that the problem was not the code.</p><p>The problem was the <strong>build structure</strong>.</p><p>After optimizing the setup, we were able to utilize all CPU cores and achieve:</p><ul><li>cold build — <strong>55 seconds</strong></li><li>incremental build — <strong>3–4 seconds on M1</strong></li></ul><p><strong>After reading this article you will</strong></p><ul><li>Understand why Asset Catalog compiles in a single thread</li><li>Learn how to parallelize compilation using <strong>Bundle targets</strong></li></ul><p><strong>What’s wrong with Asset Catalog</strong></p><p>Xcode builds a <strong>build graph</strong>. Each target represents a separate task. Inside a single target:</p><ul><li>code compilation runs in parallel</li><li>but asset compilation runs <strong>in a single thread</strong></li></ul><p>If your project has one large Assets.xcassets, the situation is simple:</p><ul><li>Xcode creates one task</li><li>it uses one CPU core</li><li>the other cores wait</li></ul><p>As a result, the entire build pipeline waits for the asset compilation to finish. That’s why a large asset catalog can slow down the whole project even on powerful hardware.</p><p><strong>The key idea</strong></p><p>Different targets can compile <strong>in parallel</strong>. And a Bundle is a separate target.</p><p>Therefore:</p><p><em>💡 One large Asset Catalog → slow</em></p><p><em>💡 Multiple Asset Catalogs in different Bundle targets → parallel compilation</em></p><p>That’s the core idea. The whole optimization is based on this principle.</p><p>We are <strong>not making the asset compiler faster</strong>.</p><p>We are simply <strong>allowing it to run in parallel</strong>.</p><p>At a high level the approach looks like this:</p><ol><li>Create a separate module (.framework) that will contain the resources</li><li>Split the Asset Catalog into several catalogs</li><li>Put each Asset Catalog into its own Bundle</li><li>Place all Bundles inside the module created in step 1</li></ol><p><em>At the end there will be a demo project on GitHub.</em></p><p><strong>Build configuration: before and after</strong></p><p>Initially we have a single large Assets.xcassets:</p><pre>App<br>└── Assets.xcassets</pre><p>One target. One task. One thread.</p><p>After restructuring it looks like this:</p><pre>App<br> └── UIResources.framework<br>       ├── ColorsBundle<br>       ├── IconsBundle<br>       ├── IllustrationsBundle<br>       └── ...</pre><p>Each Bundle is a separate target.</p><p>Each target is a separate compilation task.</p><p>These tasks can run in parallel.</p><p>The setup is not very obvious, so let’s go through the process step by step.</p><p><strong>Step‑by‑step implementation</strong></p><p><strong>Step 1. Create a module for resources</strong></p><p>Create a separate framework. I usually call it UIResources.</p><p>This module will contain the Asset Catalogs and the Bundle targets.</p><p>In Xcode choose <strong>File → New → Target → Framework</strong>, press Next, and enter the name UIResources.</p><p>Also configure the minimum deployment target.</p><p>Why use a framework:</p><ul><li>It acts as a container for all bundles</li><li>It can be imported into the main app and UI modules</li><li>It separates resources from business logic</li></ul><p>I recommend specifying the deployment target in the <strong>project file</strong> and using $(inherited) in all targets. This allows you to change the minimum iOS/macOS version in one place instead of updating every target individually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3CiFMiyCo6vOlWL81poOFw.png" /></figure><p><strong>Step 2. Split the Asset Catalog</strong></p><p>Divide the large Asset Catalog into several smaller ones.</p><p>I usually use a structure like this:</p><ul><li><strong>Colors</strong> — main colors of the design system</li><li><strong>AltColors</strong> — colors that are not part of the main palette. Sometimes integrations or experimental features require extra colors that we do not want to add to the main palette.</li><li><strong>ChromaticIcons</strong> — monochrome icons that are tinted in code</li><li><strong>ColoredIcons</strong> — multi‑color icons</li><li><strong>DesignImages</strong> — decorative design elements that we don’t want to draw in code. For example, a complex wavy line or a sparkly star. You could draw this with BezierPath and gradients, but if designers already provide a vector asset, it’s easier to use that.</li><li><strong>Illustrations</strong> — large images</li></ul><p>This structure is not only about performance. It also helps keep resources organized.</p><p>To create a new Asset Catalog, right‑click the UIResources folder in the Project Navigator and select: New File From Template… → Asset Catalog</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*_CBx_M3HmO-xNovpdR3l-w.png" /></figure><p>Separating Colors and AltColors also makes the code easier to understand and simplifies future maintenance.</p><p>For all icons in ChromaticIcons, immediately set <strong>Render As: Template Image</strong> so you don’t have to repeatedly write:</p><pre>image.withRenderingMode(.alwaysTemplate)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*p0Q5h0EGnLmACr7S0ghQ5Q.png" /></figure><p>Chromatic icons are designed to be tinted dynamically depending on context.</p><p><strong>Step 3. Create Bundle targets</strong></p><p>Now the interesting part. We need to create <strong>one Bundle target for each Asset Catalog</strong>.</p><p>In the demo project I created four catalogs, which is enough to demonstrate the idea.</p><p>By default, the <strong>Bundle</strong> target type is not available for iOS.</p><p>You can find it under the <strong>macOS</strong> section.</p><p>Create bundles via <strong>File → New → Target → macOS → Bundle</strong>, for example:</p><ul><li>ColorsBundle</li><li>ChromaticIconsBundle</li><li>ColoredIconsBundle</li><li>IllustrationsBundle</li></ul><p>Yes, through macOS — and that’s fine. After creating them we will simply change the supported platform.</p><p>Each bundle becomes a separate task in the build graph.</p><p>After creating the bundles, update the platform settings:</p><ol><li>Open the list of targets</li><li>Select all created bundles and the project file they belong to</li><li>Open <strong>Build Settings</strong> and find Supported Platforms</li><li>Set Supported Platforms to the platforms you need (iOS in the demo project)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rhlOU5KzKXBTNMLGRoskzA.png" /></figure><p><strong>Step 4. Configure dependencies</strong></p><p>Now we need to connect everything correctly.</p><p>The Asset Catalogs we created earlier currently belong to the UIResources module, so we need to adjust the configuration.</p><p>Select the UIResources target and go to <strong>Build Phases → Copy Bundle Resources</strong>, then:</p><ul><li>Remove the asset catalogs from Copy Bundle Resources</li><li>Add the created bundles there</li><li>Add these bundles to <strong>Target Dependencies</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJBCzkr15T0Bkdze17vSyw.png" /></figure><p>Next, open each Bundle target, go to <strong>Copy Bundle Resources</strong>, and add the corresponding Asset Catalog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pwcV37C4CCMDcIFYWitQQQ.png" /></figure><p><strong>One bundle — one catalog.</strong></p><p>PS: The UIResources module itself (like any .framework) is also a bundle.</p><p>So we end up with <strong>a bundle that contains other bundles</strong>.</p><p>If everything is done correctly, the Asset catalog will be related to the Bundle target:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CD67jqZtlfWEjn-p1TiiqQ.png" /></figure><p><strong>Verification</strong></p><p>Build the project and open the <strong>Build Timeline</strong>. You should see that the Asset Catalogs are compiled <strong>in parallel</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9t8Zybj-1BShxLpsy8Zjng.png" /></figure><p>Now CPU usage during the build looks much better — the processor finally uses multiple cores for compiling resources.</p><p><strong>Why this works</strong></p><ul><li>Xcode compiles each target separately</li><li>The asset compiler inside a target is single‑threaded</li><li>Different targets can compile in parallel</li><li>A Bundle is a separate target</li></ul><p>As a result, asset compilation runs in parallel.</p><p>Moreover, UIResources compiles <strong>in parallel with modules that contain code</strong>.</p><p>We did not speed up the compiler itself — we <strong>changed the structure of the build pipeline</strong>.</p><p>Sometimes optimization is not about micro‑tuning.</p><p>Sometimes it’s about <strong>proper decomposition</strong>.</p><p><strong>Accessing resources</strong></p><p>Assets are no longer located in the main bundle. To access them we need a small helper.</p><pre>fileprivate let currentBundle = Bundle(for: BundleToken.self)<br>fileprivate final class BundleToken {}<br><br>public enum ChromaticIcons {<br>    internal static let assetBundlePath: String = currentBundle.path(forResource: &quot;ChromaticIconsBundle&quot;, ofType: &quot;bundle&quot;)!<br>    internal static let assetBundle: Bundle = Bundle(path: assetBundlePath)!<br>}<br><br>@available(iOS 17.0, *)<br>extension ImageResource {<br>    public static var chromaticIcons: ChromaticIcons.Type { ChromaticIcons.self }<br>}<br><br>extension ChromaticIcons {<br>    public static let sms = ImageResource(name: &quot;SMS&quot;, bundle: Self.assetBundle)<br>}</pre><p>Of course, writing this code manually would be tedious.</p><p>In the next article we’ll talk about <strong>code generation</strong>. It removes this boilerplate, prevents errors from string literals, and provides a convenient syntax with autocomplete:</p><pre>Image(.chromaticIcons.sms)<br>  .foregroundStyle(.orange)</pre><p><strong>When you should not use this approach</strong></p><p>Do not complicate your build structure if:</p><ul><li>Your project has only a small number of assets</li><li>Asset compilation takes less than <strong>15 seconds</strong></li><li>Your team is not ready to maintain a more complex build graph</li></ul><p><strong>Summary</strong></p><p>With this approach we:</p><ul><li>Removed a build bottleneck</li><li>Utilized more CPU cores</li><li>Reduced cold build time</li><li>Created a scalable structure for future growth</li></ul><p><strong>The demo project is here: </strong><a href="https://github.com/iDmitriyy/DemoProjects">github.com/iDmitriyy/DemoProjects</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8d1d520a4da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nested tuples: Denestifying]]></title>
            <link>https://medium.com/@dy.ignatyev/nested-tuples-denestifying-e4b31649caac?source=rss-83f7767d105e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4b31649caac</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[functional-swift]]></category>
            <category><![CDATA[tuples]]></category>
            <category><![CDATA[rxswift]]></category>
            <dc:creator><![CDATA[Dmitriy Ignatyev]]></dc:creator>
            <pubDate>Tue, 19 May 2020 10:42:41 GMT</pubDate>
            <atom:updated>2020-05-19T19:51:43.601Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L6jR9KSYTshpiikC4CuSNg.png" /></figure><p>If you have worked with RxSwift, then you might know that using some operators leads to the appearance of nested tuples.</p><p>Something like these:<br>(((AuthToken, String), Profile), ScreenDataModel)<br>((AuthToken, String), (Profile, ScreenDataModel))<br>((AuthToken, String), Profile, ScreenDataModel)<br>etc., there is plenty of combinations.</p><p>The most often used operators giving such tuples are ‘Combinelatest’ and ‘WithLatestFrom’ operator.</p><p>I’m not going to write lots of text this time, just some explanatory examples.<br>Here is example code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4WCfJ0BtHFFbgUHBACLIYA.png" /></figure><p>The compiler gives us an error. Unfortunately, we can’t write closure’s arguments list as usual. <br>That is because closure parameter $0 is of type (((AuthToken, String), Profile), ScreenDataModel) — a tuple inside another tuple inside another tuple.</p><p>We can use map() operator, extract all parameters and make a flat list from them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RsxMaz1Tb5DbCgxEyMZIew.png" /></figure><p>After that, we can use use closure’s parameters in the usual way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R_s-Yu0Bvat99c-BqRAwyA.png" /></figure><p>Instead of writing this map {} operator every time we want to get a flat closure’s parameters list, we can write several functions, that denestify tuple parameters.</p><p>The example above will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YvBG70qCziek7Pr9WHTw2w.png" /></figure><p>The implementation:<br><a href="https://gist.github.com/iDmitriyy/cfe46190eae605ebc1dc445c36a44648">https://gist.github.com/iDmitriyy/cfe46190eae605ebc1dc445c36a44648</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4b31649caac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AppVersion Model]]></title>
            <link>https://medium.com/macoclock/appversion-model-44b7a99b66da?source=rss-83f7767d105e------2</link>
            <guid isPermaLink="false">https://medium.com/p/44b7a99b66da</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[app-version]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Dmitriy Ignatyev]]></dc:creator>
            <pubDate>Sat, 09 May 2020 20:32:35 GMT</pubDate>
            <atom:updated>2020-05-21T09:59:45.744Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OOH4TdWFwTGxBm2WABzxrA.png" /></figure><p>There are a variety of features that depends on app version:</p><ul><li>show app version in “About screen”</li><li>send it to analytics</li><li>send it to your backend with network requests</li><li>send it in the meta information of support chat messages</li><li>make database migration after the app update</li><li>show some kind of notifications/reminder to the user after minor version updates</li><li>and so on…</li></ul><p>As you might know, we can get app version from Bundle info dict:</p><pre>if let version = Bundle.main.infoDictionary?[&quot;CFBundleShortVersionString&quot;] as? String {<br>  … // version 2.17.1<br>}</pre><pre>if let builNumber = Bundle.main.infoDictionary?[&quot;CFBundleVersion&quot;] as? String {<br>  … // builNumber 953<br>}</pre><p>There are several inconveniences in this approach:</p><p>1. We are forced to use if-let construction every time we need to get app version or use nil coalescing operator</p><p>2. Repeat boilerplate code: Bundle.main.infoDictionary?[“CFBundleShortVersionString”] as? String</p><p>3. Repeat boilerplate code to extract major / minor / patch components:</p><pre>If let version = Bundle.main.infoDictionary?[&quot;CFBundleShortVersionString&quot;] as? String {<br>  let components = currentVersion.components(separatedBy: &quot;.&quot;)</pre><pre>let majorString = components[0] // &quot;2&quot;<br>  let minorString = components[1] // &quot;17&quot;<br>  let patchString = components[2] // &quot;1&quot;</pre><pre>// and after that convert string to Int<br>  let major = Int(majorString)! // force unwrapping or if-let cinstruction once again <br>}</pre><p>4. No ability to correctly compare two versions. Let’s see an example:</p><pre>  let previousVersion = &quot;2.9.0&quot;<br>  let currentVersion = &quot;2.17.0&quot;<br>  <br>  previousVersion &lt; currentVersion // false. It isn’t correct result.</pre><p>This is our improvement plan:</p><p>☐ get rid of meaningless if-let constructions or usage of nil coalescing operator</p><p>☐ get rid boilerplate code to get app version from Bundle’s userinfo</p><p>☐ get rid boilerplate code to extract major / minor / patch components</p><p>☐ add an ability to correctly compare two versions</p><p>Let’s try to fix all these minuses. First of all, we improve the standard Foundation Api:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7faf06556c18bbf3cca261bdaf566cf7/href">https://medium.com/media/7faf06556c18bbf3cca261bdaf566cf7/href</a></iframe><p>First two items are completed:</p><p>☑ get rid of meaningless if-let constructions or usage of nil coalescing operator</p><p>☑ get rid boilerplate code to get app version from Bundle’s userinfo</p><p>Very good, let’s go further.</p><p>Now, we create an AppVersion model:</p><pre>public struct AppVersion: LosslessStringConvertible {<br>  public let major: Int<br>  public let minor: Int<br>  public let patch: Int<br>}</pre><p>Next step is to make full implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b94f0b136600edcf97ce9847ae412304/href">https://medium.com/media/b94f0b136600edcf97ce9847ae412304/href</a></iframe><p>Next step is to make AppVersion comparable:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/609d8fb2bbf0bbc61fc4509c1b657e19/href">https://medium.com/media/609d8fb2bbf0bbc61fc4509c1b657e19/href</a></iframe><p>One more optional step is to make it Codable. In my case it is needed, but you can omit this.</p><pre>extension AppVersion: Codable {<br>  public init(from decoder: Decoder) throws {<br>    let container = try decoder.singleValueContainer()</pre><pre>let components: [Int] = try container.decode([Int].self)<br>    self = AppVersion.fromComponents(components: components)<br>  }</pre><pre>public func encode(to encoder: Encoder) throws {<br>    var container = encoder.singleValueContainer()<br>    try container.encode(components)<br>  }<br>}</pre><p>Finally, we add two additional static properties to Bundle extension:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dabcbe0e1e2da32250d5d9c8e4e4606c/href">https://medium.com/media/dabcbe0e1e2da32250d5d9c8e4e4606c/href</a></iframe><p>Besides, we can store the app version of the previous launch:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ad6f1a3f1f140bfaec061160babeed3/href">https://medium.com/media/0ad6f1a3f1f140bfaec061160babeed3/href</a></iframe><p>Let’s see the result:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d7828d4007f9bf027ae1751c55e4701/href">https://medium.com/media/0d7828d4007f9bf027ae1751c55e4701/href</a></iframe><p>All goals are achieved: 💪🏼</p><p>☑ get rid of meaningless if-let constructions or usage of nil coalescing operator</p><p>☑ get rid boilerplate code to get app version from Bundle’s userinfo</p><p>☑ get rid boilerplate code to extract major / minor / patch components</p><p>☑ add an ability to correctly compare two versions</p><p>Link to the final code: <a href="https://gist.github.com/iDmitriyy/79f288c0bb6a8cbb22c59f8ecb54a9fc">https://gist.github.com/iDmitriyy/79f288c0bb6a8cbb22c59f8ecb54a9fc</a></p><p>If you are not familiar with Semantic Versioning 2.0.0, I recommend you to read this article:<br><a href="https://semver.org/">https://semver.org</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44b7a99b66da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/macoclock/appversion-model-44b7a99b66da">AppVersion Model</a> was originally published in <a href="https://medium.com/macoclock">Mac O’Clock</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Combining Parallel Network Requests]]></title>
            <link>https://medium.com/@dy.ignatyev/combining-parallel-network-requests-ee60fb85369?source=rss-83f7767d105e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee60fb85369</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[combined-resources]]></category>
            <category><![CDATA[urlrequest]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Dmitriy Ignatyev]]></dc:creator>
            <pubDate>Sun, 08 Dec 2019 09:55:03 GMT</pubDate>
            <atom:updated>2020-01-05T09:21:46.103Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vINrFaal_JCzAPjh1i9Ajw.png" /></figure><p>Sometimes we need to perform several URL requests in parallel, and when all of them are completed — combine all responses into a single result.</p><p>As you might know, there are different ways to do it, such as GCD or OperationQueue. You can also use 3d party libraries, such as PromiseKit, Bolts or RxSwift.</p><p>But in reality, not everyone have theese libraries in the project. In addition, a lot of developers don’t want to add them for some reasons. You might also don’t want to use GCD primitives directly every time.</p><p>In my case for example, we have RxSwift in our project. But we reasonably don’t want to make our ApiManager reactive.</p><p>So, what the solution?</p><p>We can use DispatchGroup for performing several requests and waiting until all of them are completed. But using it directly looks awkward in some cases, and it is easy to make a mistake.<br>Such code is also a kind of boilerplate and doesn’t comply with the DRY principle.</p><p>I have made utility method, that helps to combine several network requests easily. Its usage looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5f59956fae16637fd10cd1f5979fb9e/href">https://medium.com/media/a5f59956fae16637fd10cd1f5979fb9e/href</a></iframe><p>In the bottom you can find a link to Playground.</p><p>Let’s take a look at how it works under the hood.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17f8e44bb3bb76cd82ec37d2059c598a/href">https://medium.com/media/17f8e44bb3bb76cd82ec37d2059c598a/href</a></iframe><p>In our app, there are about 30 screens where we need to combine data from different backend APIs. Lets discuss one of them.<br>On the main screen we need to load 4 portions of data:<br>- User profile<br>- Balance info<br>- Tariff info<br>- Special offers</p><p>In purpose of making example more understandable, I’m using simplified requests:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55893f5e4f1048636edbd68339cedd4a/href">https://medium.com/media/55893f5e4f1048636edbd68339cedd4a/href</a></iframe><p>As you see, we use Result&lt;S, F&gt; enum in completions. And almost always, we want to get success data from all results, or an error if at least one request failed.<br>For this case, I have made one more help method that unwraps all the results.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44c5b0b364d82febd57e85b2fe138e40/href">https://medium.com/media/44c5b0b364d82febd57e85b2fe138e40/href</a></iframe><p>Now, it is time to show how it works all together.</p><p>Firstly, we need to wrap every network request with a non-escaping closure.<br>Eeach wrapping closure takes network request completion as an argument</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c8c2f5b8ec60952fc7f73a8fb7c7adb/href">https://medium.com/media/4c8c2f5b8ec60952fc7f73a8fb7c7adb/href</a></iframe><p>You can find playground here:<br><a href="https://github.com/smartappdeveloop/ParallelUrlRequest">https://github.com/smartappdeveloop/ParallelUrlRequest</a><br>At the end of this playground you will find more complex example where 8 network requests are combined. You can easily combine up to 16 if needed.</p><p>If you want to use this approach in your project, just copy UrlParallelRequest.swift file from repository.</p><p>This is my first article, I hope you enjoyed it :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee60fb85369" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>