<?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 Alex Logan on Medium]]></title>
        <description><![CDATA[Stories by Alex Logan on Medium]]></description>
        <link>https://medium.com/@swiftyalex?source=rss-73ca19e68497------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CU5-CudXa64MOEAl1bXEHg@2x.jpeg</url>
            <title>Stories by Alex Logan on Medium</title>
            <link>https://medium.com/@swiftyalex?source=rss-73ca19e68497------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 19:51:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swiftyalex/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[Networking with Async Await]]></title>
            <link>https://swiftyalex.medium.com/networking-with-async-await-b9e7e9249b51?source=rss-73ca19e68497------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9e7e9249b51</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[wwdc]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Alex Logan]]></dc:creator>
            <pubDate>Mon, 21 Jun 2021 19:15:48 GMT</pubDate>
            <atom:updated>2021-06-21T19:24:31.518Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J7QtvC_1Ut9lrfqFRBw5Gg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@iambobnelson?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Robert Nelson</a> on <a href="https://unsplash.com/s/photos/flat-white?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>At some point as iOS engineers, we’ve all had to deal with some messy network code. Whilst the closure based syntax of async work in Swift can be managed, with more complex operations things can get out of hand pretty quickly.</p><p>Now we have async await, we can say goodbye to code that looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c12e260f0ba2925d14337a91eee2978/href">https://medium.com/media/7c12e260f0ba2925d14337a91eee2978/href</a></iframe><p>Whilst it might seem like ive created a purposefully hard to read example of a networking call here, I’ve found very similar looking code in <em>many</em> apps I’ve worked on — including my own ( I’m looking at you Bike Settings 1.0 ).</p><h4>Making Requests</h4><p>async networking is wonderfully simple to use. There’s some new methods on URLSession that will do the heavy lifting for us. <br> The basic new look for networking is this. We can await the new async data(from: URL) which will return a tuple of the data and response. The response is a basic URLResponse, you&#39;ll most likely want to cast that to an HTTPURLResponse instead to read status codes.</p><p>*If you’re not too familiar with async yet, don’t worry — its brand new. I’ll be covering the basics of async in a later post.*</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a105d29423e35a45727d72a36be10ceb/href">https://medium.com/media/a105d29423e35a45727d72a36be10ceb/href</a></iframe><p>We have to mark our calls to URLSession methods with try as they can throw errors just like usual. This means we should either wrap in a do catch, or mark the function that calls this with async throws.<br> If you want to do more than just get something, you can also perform URLRequests with a similar method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf164ca02dcd72a7afa6f350c96afda6/href">https://medium.com/media/bf164ca02dcd72a7afa6f350c96afda6/href</a></iframe><p>Lets look at a more complete example, that adds an authentication header, makes a request, then decodes the response into a Codable. This is exactly the same as the code we saw in the intro, but using our new async methods to clean things up.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba4f4a9d7e425a9703b3a6e36ba5c85d/href">https://medium.com/media/ba4f4a9d7e425a9703b3a6e36ba5c85d/href</a></iframe><p>If we break that down, its doing quite a lot, and its all very readable. It gets a token, which could itself perform a network request, checks the response code is valid, then returns a decoded JSON.</p><p>This setup code will be very familiar to you because its exactly what you’d do now — the cool part is waiting for our result without using closures.</p><p>if you wanted to upload some data instead, its just a couple small changes. Set the method to post, and attatch the json data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab96aae380cbbed6d8cefece2dc84237/href">https://medium.com/media/ab96aae380cbbed6d8cefece2dc84237/href</a></iframe><h4>Downloading &amp; Uploading</h4><p>We’re not always just posting or asking for JSON — sometimes we have more to do. Its quite common to have to deal with file uploads, such as profile pictures, and we’re luckily going to get some help here too.</p><p>Uploading has a similar new method to data tasks, upload(for: URLRequest, from: Data) and using it looks something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d07f72d71dc714ea1a3e16d0e3a91e04/href">https://medium.com/media/d07f72d71dc714ea1a3e16d0e3a91e04/href</a></iframe><p>Downloading is just as simple, with download(for: URLRequest). The setup code in all these examples is just about the same, with just some method changes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c65b92ebff0db17991ddc5f7d149684/href">https://medium.com/media/3c65b92ebff0db17991ddc5f7d149684/href</a></iframe><p>The URL returned here will contain our downloaded file. If you use the sample code and open tyhat URL, you will find the file with a .tmp extension.</p><h3>Conclusion</h3><p>That was a quick intro to how you can use async/await in your codebase for networking. Its nice and simple, with scope to really clean up your code. All I’ve shown today is what its like at the network point — this cleanup continues as you go through the layers of your app.</p><p>Head to the <a href="https://github.com/SwiftyAlex/Samples/tree/main/001-async-networking/001-async-networking.playground">repo</a> and open 001-async-networking to run this code for yourself. You’ll find fully working code samples ( with exceptions for where I don’t have any mock endpoints — sorry! ) that you can lift and take into your own projects. For a challenge, why not try displaying a list of characters in a SwiftUI list?</p><p>If you’d like to take this even further, you could even build a full network stack using the new await apis based on the code i’ve provided. I would suggest going around and removing some duplicated code from my examples, and considering adding a nice typed system to represent endpoints.</p><p>If you fancy reading a little more, I’m <a href="https://twitter.com/swiftyalex">@SwiftyAlex</a> on twitter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9e7e9249b51" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS 14 and Big Sur Navigation]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/ios-14-and-big-sur-navigation-ae11a7efdf29?source=rss-73ca19e68497------2"><img src="https://cdn-images-1.medium.com/max/2600/1*pPqtznA6nzzi8xh3zU4ZDg.jpeg" width="3264"></a></p><p class="medium-feed-snippet">Master navigation in the modern Apple ecosystem with sidebars and tab bars</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/ios-14-and-big-sur-navigation-ae11a7efdf29?source=rss-73ca19e68497------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/ios-14-and-big-sur-navigation-ae11a7efdf29?source=rss-73ca19e68497------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae11a7efdf29</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ipad]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Alex Logan]]></dc:creator>
            <pubDate>Wed, 09 Dec 2020 16:14:36 GMT</pubDate>
            <atom:updated>2020-12-14T19:35:33.806Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Feature Flags for iOS]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/feature-flags-5ff6be0a4568?source=rss-73ca19e68497------2"><img src="https://cdn-images-1.medium.com/max/1920/1*eZsJ2fblnxV7m-Ws9pNNgw.jpeg" width="1920"></a></p><p class="medium-feed-snippet">Learn how to speed up your development process with feature flags, including some SwiftUI examples.</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/feature-flags-5ff6be0a4568?source=rss-73ca19e68497------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/feature-flags-5ff6be0a4568?source=rss-73ca19e68497------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ff6be0a4568</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[features]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Alex Logan]]></dc:creator>
            <pubDate>Tue, 21 Jul 2020 17:33:47 GMT</pubDate>
            <atom:updated>2020-07-22T09:35:42.226Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Getting Your App Ready for iOS 14]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/getting-ready-for-ios-14-7cffcf198239?source=rss-73ca19e68497------2"><img src="https://cdn-images-1.medium.com/max/1960/1*FlgVMlPHSmZ7l31oKZwRaA.jpeg" width="1960"></a></p><p class="medium-feed-snippet">Get your UI and your users ready for what&#x2019;s coming this year at WWDC</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/getting-ready-for-ios-14-7cffcf198239?source=rss-73ca19e68497------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/getting-ready-for-ios-14-7cffcf198239?source=rss-73ca19e68497------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cffcf198239</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Alex Logan]]></dc:creator>
            <pubDate>Fri, 22 May 2020 09:30:18 GMT</pubDate>
            <atom:updated>2020-09-27T10:49:41.436Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[3 Ways to Customise Your Views in SwiftUI]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/three-ways-to-customise-your-views-in-swiftui-94b08cd09f3f?source=rss-73ca19e68497------2"><img src="https://cdn-images-1.medium.com/max/2400/1*v20A1MLTxIVQ2iS31mR7JA.jpeg" width="2400"></a></p><p class="medium-feed-snippet">Custom views are great, but how can we make them feel Swiftier?</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/three-ways-to-customise-your-views-in-swiftui-94b08cd09f3f?source=rss-73ca19e68497------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/three-ways-to-customise-your-views-in-swiftui-94b08cd09f3f?source=rss-73ca19e68497------2</link>
            <guid isPermaLink="false">https://medium.com/p/94b08cd09f3f</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Alex Logan]]></dc:creator>
            <pubDate>Tue, 07 Apr 2020 19:22:24 GMT</pubDate>
            <atom:updated>2020-04-09T15:34:06.984Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[5 Property Wrappers to Declutter Your iOS Code]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/five-property-wrappers-to-de-clutter-your-ios-code-f5ee6fa4e52e?source=rss-73ca19e68497------2"><img src="https://cdn-images-1.medium.com/max/2600/1*DUXPYr8i_kQFITAnHlnJIA.jpeg" width="4608"></a></p><p class="medium-feed-snippet">You may be familiar with @State and @EnvironmentObject, here are 5 more</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/five-property-wrappers-to-de-clutter-your-ios-code-f5ee6fa4e52e?source=rss-73ca19e68497------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/five-property-wrappers-to-de-clutter-your-ios-code-f5ee6fa4e52e?source=rss-73ca19e68497------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5ee6fa4e52e</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Alex Logan]]></dc:creator>
            <pubDate>Sat, 14 Mar 2020 14:56:39 GMT</pubDate>
            <atom:updated>2020-03-17T00:32:35.741Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Scalable Routing in Swift]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/scalable-routing-in-swift-d584c9ff728b?source=rss-73ca19e68497------2"><img src="https://cdn-images-1.medium.com/max/2600/1*PSU_8cZGSxcKJjlpsJpS9A.jpeg" width="6000"></a></p><p class="medium-feed-snippet">With a sprinkling of Combine</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/scalable-routing-in-swift-d584c9ff728b?source=rss-73ca19e68497------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/scalable-routing-in-swift-d584c9ff728b?source=rss-73ca19e68497------2</link>
            <guid isPermaLink="false">https://medium.com/p/d584c9ff728b</guid>
            <category><![CDATA[combine]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[foundation]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Alex Logan]]></dc:creator>
            <pubDate>Sun, 22 Sep 2019 16:27:14 GMT</pubDate>
            <atom:updated>2019-09-24T00:01:48.324Z</atom:updated>
        </item>
    </channel>
</rss>