Unit testing Swift code that uses async/await
Writing robust and predictable unit tests for asynchronous code has always been particularly challenging, given that each test method is executed completely serially, line by line (at least when using...
View ArticlePodcast: “Code maintenance”, with special guest Nick Lockwood
Nick Lockwood joins John for a discussion about maintaining Swift code bases — from open source projects, to ones worked on by teams of various sizes. Also, the design of ShapeScript, using async/await...
View ArticleSwift actors: How do they work, and what kinds of problems do they solve?
Since the very first version of Swift, we’ve been able to define our various types as either classes, structs, or enums. But now, with the launch of Swift 5.5 and its built-in concurrency system, a new...
View ArticleWhat role do Tasks play within Swift’s concurrency system?
When writing asynchronous code using Swift’s new built-in concurrency system, creating a Task gives us access to a new asynchronous context, in which we’re free to call async-marked APIs, and to...
View ArticlePodcast: “Concurrency beyond app development”, with special guest Tim Condon
Tim Condon joins John to discuss how both client and server-side Swift developers could utilize the new built-in concurrency system, as well as how distributed actors and other upcoming language...
View ArticleLightweight dependency injection and unit testing using async functions
Very often, making code easy to unit test tends to go hand-in-hand with improving that code’s separation of concerns, its state management, and its overall architecture. In general, the more...
View ArticleDelaying an asynchronous Swift Task
Most often, we want our various asynchronous tasks to start as soon as possible after they’ve been created, but sometimes we might want to add a slight delay to their execution — perhaps in order to...
View ArticleNew Discover page: Concurrency
Explore Swift’s built-in concurrency system, and how to use tools like async/await and actors to write concurrent code in robust and efficient ways.→ Check it out
View ArticlePodcast: “Custom rendering”, with special guest James Thomson
James Thomson returns to the show to discuss the various technologies that enable us to render custom UIs on Apple’s platforms. From rendering views using Core Graphics and Core Animation, to building...
View ArticleBuilding an asynchronous SwiftUI button
When building modern applications, it’s incredibly common to want to trigger some form of asynchronous action in response to a UI event. For example, within the following SwiftUI-based PhotoView, we’re...
View ArticlePodcast: “The 2021 Season Finale”
To wrap up the 2021 season of the show, John revisits some of the key themes and topics that were discussed both on the show itself, and within the Swift community in general, throughout the...
View ArticleTwo ways of capturing self strongly within a closure
In Swift, there are two ways to capture self as a strong reference within an escaping closure. The first is to explicitly use the self keyword whenever we’re calling a method or accessing a property on...
View ArticleCreating Combine-compatible versions of async/await-based APIs
A challenge that many developers face as they maintain various code bases over time is how to neatly connect different frameworks and APIs in a way that properly adheres to the conventions of each...
View ArticleBasics: Loops
Swift offers many different built-in ways to iterate over collections (such as arrays, sets, and dictionaries) — the most basic of which being for loops, which let us run a piece of code for each...
View ArticleBackgrounds and overlays in SwiftUI
SwiftUI offers several different ways for us to create stacks of overlapping views that can be arranged along the Z axis, which in turn enables us to define various kinds of overlays and backgrounds...
View ArticleAutomatically retrying an asynchronous Swift Task
Sometimes, we might want to automatically retry an asynchronous operation that failed, for example in order to work around temporary network problems, or to re-establish some form of connection.Here...
View ArticleMemory management when using async/await in Swift
Managing an app’s memory is something that tends to be especially tricky to do within the context of asynchronous code, as various objects and values often need to be captured and retained over time in...
View ArticleCombining protocols in Swift
One of the core strengths of Swift’s protocols is that they enable us to define shared interfaces that multiple types can conform to, which in turn lets us interact with those types in a very uniform...
View ArticleWriting testable code when using SwiftUI
A major part of the challenge of architecting UI-focused code bases tends to come down to deciding where to draw the line between the code that needs to interact with the platform’s various UI...
View ArticlePodcast: “Where is Swift headed in 2022?”, with special guest JP Simard
On this 2022 season premiere, JP Simard returns to the show to discuss what’s next for Swift in 2022, and what kinds of improvements and new features that might be coming to the language during the...
View ArticleBasics: Equality
Checking whether two objects or values are considered equal is definitely one of the most commonly performed operations in all of programming. So, in this article, let’s take a look at how Swift models...
View ArticleSponsor: Judo
My thanks to Judo for sponsoring Swift by Sundell — both the website and the podcast — during this first quarter of the year. Those of you who have been following my work for a while might know that...
View ArticleAbstract types and methods in Swift
In object-oriented programming, an abstract type provides a base implementation that other types can inherit from in order to gain access to some kind of shared, common functionality. What separates...
View ArticlePodcast: “Accessibility on Apple’s platforms”, with special guest Sommer Panage
Sommer Panage returns to the show to discuss Apple’s various accessibility APIs and tools, how to incorporate accessibility support into a team’s overall development workflow, and what it was like...
View ArticleType placeholders in Swift
Swift’s type inference capabilities have been a very core part of the language since the very beginning, and heavily reduces the need for us to manually specify types when declaring variables and...
View ArticlePodcast: “A framework and an app”, with special guest Simon Støvring
Simon Støvring returns to the show to talk about how he built his new text editor Runestone, how to effectively manage an app’s settings, performance tuning, and implementing an app’s core logic as a...
View ArticleSwift by Sundell turns five years old today! Here’s what’s next for the...
Today it’s been exactly five years since this website first launched, and what a journey it has been! When I started this website after having published weekly articles on Medium for a few months, I...
View ArticlePodcast: “The evolution of SwiftUI”, with special guest Chris Eidhof
Chris Eidhof returns to the podcast to talk about how SwiftUI has evolved since its initial release, to share several key learnings from using it over the past few years, and to discuss concepts like...
View ArticleRendering SwiftUI views within UITableView or UICollectionView cells on iOS 16
Ever since its original introduction in 2019, SwiftUI has had really strong interoperability with UIKit. Both UIView and UIViewController instances can be wrapped to become fully SwiftUI-compatible,...
View ArticleSwift 5.7’s new optional unwrapping syntax
Swift 5.7 introduces a new, more concise way to unwrap optional values using if let and guard let statements. Before, we always had to explicitly name each unwrapped value, for example like this:class...
View ArticleUsing the ‘some’ and ‘any’ keywords to reference generic protocols in Swift 5.7
Combining Swift’s flexible generics system with protocol-oriented programming can often lead to some really powerful implementations, all while minimizing code duplication and enabling us to establish...
View ArticlePodcast: “Swift 5.7, generics, and the road to Swift 6”, with special guest...
Ben Cohen, manager of the Swift team at Apple, joins John on this WWDC22 special to discuss Swift 5.7, how generics have been made more powerful and easy to use, and how the language is expected to...
View ArticleSwitching between SwiftUI’s HStack and VStack
SwiftUI’s various stacks are some of the framework’s most fundamental layout tools, and enable us to define groups of views that are aligned either horizontally, vertically, or stacked in terms of...
View ArticlePodcast: “What’s new in SwiftUI in iOS 16?”, with special guest Natalia...
Natalia Panferova joins John to discuss some of the key new features that are coming to SwiftUI and UIKit in iOS 16, and to talk about her experience working on SwiftUI at Apple.SponsorsNordVPN: Get an...
View ArticleSponsored: Essential Developer
Thanks a lot to Caio and Mike, the two developers behind Essential Developer, for sponsoring Swift by Sundell. Essential Developer was founded to help iOS developers accelerate their journeys towards...
View ArticlePodcast: “The role of system design”, with special guest Gui Rambo
Gui Rambo returns to the show to talk about the role and importance of system design when building apps and open source tools, and how common app architectures and design patterns can be augmented with...
View ArticlePodcast: “Freelancing and WWDC22 highlights”, with special guest Donny Wals
Donny Wals returns to the show to talk about being an iOS developer freelancer, and to discuss some of the key new APIs, Swift language features, and frameworks that were introduced at...
View ArticlePodcast: “Responsive and smooth UIs”, with special guest Adam Bell
Adam Bell returns to the podcast to discuss different techniques and approaches for optimizing UI code, and how to utilize tools like animations in order to build iOS apps that feel fast and...
View ArticleCombining opaque return types with primary associated types
Ever since Swift was first introduced, it’s been very common to need to use type erasure when working with generic protocols — ones that either reference Self within their requirements, or make use of...
View ArticlePodcast: “Swift concurrency in practice”, with special guest Ben Scheirman
Ben Scheirman returns to the show to discuss how Swift’s built-in concurrency features, such as async/await and tasks, can be used in practice when building apps for Apple’s platforms.SponsorsEssential...
View ArticlePodcast: “The evolution of Swift”, with special guest Nick Lockwood
On this final episode of 2022, Nick Lockwood returns to the show to discuss the overall evolution of Swift and its ecosystem of tools and libraries. How has Swift changed since its original...
View ArticleObserving the content offset of a SwiftUI ScrollView
When building various kinds of scrollable UIs, it’s very common to want to observe the current scroll position (or content offset, as UIScrollView calls it) in order to trigger layout changes, load...
View ArticleSwiftUI views versus modifiers
One of the most interesting aspects of SwiftUI, at least from an architectural perspective, is how it essentially treats views as data. After all, a SwiftUI view isn’t a direct representation of the...
View ArticleSwift by Sundell is back!
I never actually decided to stop writing Swift articles. It just sort of happened. In fact, for the past two years as this website has been very much dormant, I’ve lost count of the number of times...
View ArticleModern URL construction in Swift
These days, most applications need to work with URLs in some form. Perhaps they’re used to make network calls, to read and write files, or to perform various kinds of database operations. In Swift,...
View ArticleUsing Swift’s defer keyword within async and throwing contexts
Swift’s defer keyword allows us to delay the execution of a given block of code until the current scope is exited. While that might initially not seem that useful (after all, can’t we simply write that...
View ArticleTips and tricks for when using SwiftUI’s ViewBuilder
SwiftUI’s ViewBuilder type is a key part of the library’s overall API design, in that it’s what enables multiple view expressions to be declared within a given scope (such as a body property...
View ArticleDecoding Swift types that require additional data
Swift’s Codable API — which consists of the Encodable protocol for encoding, and Decodable for decoding — offers a powerful, built-in mechanism for converting native Swift types to and from a...
View ArticleDeciding between ‘let’ and ‘var’ for Swift struct properties
When declaring a Swift property, we use either the let or var keyword depending on whether we want our new property to be read-only once assigned through the enclosing type’s initializer, or whether we...
View ArticleBuilding a design system at Genius Scan
As an app’s code base grows and evolves, it can be really tricky to maintain consistency within its UI. It’s easy for things like margins and padding, or colors and fonts, to start diverging, as...
View Article