Designing reusable Swift libraries
This week’s article is about library development, and contains a few techniques and principles that can be good to keep in mind when designing and building reusable Swift libraries.
Articles, podcasts and news about Swift development, by John Sundell.
This week’s article is about library development, and contains a few techniques and principles that can be good to keep in mind when designing and building reusable Swift libraries.
Let’s take a look at how even the smallest utility functions can have quite a big impact on the way we write code on a day-to-day basis, by making common tasks easier and preferred patterns simpler.
The phrase “Swifty code” is often used to describe code that follows the conventions that are currently the most popular within the Swift community. But what exactly does that entail? Let’s take a look.
An overview of Swift’s five different levels of access control, how they work, and when each of them might be useful in practice.
Let’s take a look at one of the core aspects of object-oriented programming — initialization. What characteristics should an initializer ideally have, and what sort of techniques could be useful in order to keep our initializers simple and predictable?
Predicates can enable us to filter various collections in ways that are incredibly flexible. Let’s take a look at how we could construct powerful, type-safe predicates using closures, generics, and operators.
This week, let’s take a look at a few core language features that enable us to design really lightweight APIs in Swift, and how we can use them to make a feature or system much more capable through the power of composition.
A look behind the scenes of Swift by Sundell, as well as a preview and live demo of my suite of static site generation tools.
Josh Shaffer, engineering director with the UIKit and SwiftUI team at Apple, joins John to go on a deep dive into SwiftUI. What inspired the creation and design of SwiftUI, how does it impact the way apps are developed and architected, how is Apple using and improving SwiftUI internally, and much more.
When designing APIs, using default arguments can often let us strike a nice balance between flexibility and ease of use — as they let us add solid, intuitive defaults to many of the configuration options that we’ll end up providing. Let’s take a look at a few examples of how they may be used.
Marin Todorov joins John to talk about bridging the gap between UIKit, Combine and SwiftUI, how to design intuitive and robust APIs, and how the developer community can augment Apple’s SDKs through open source.
Let’s take a look at how caching can be an incredibly powerful tool in various situations, how to build an efficient and elegant caching API in Swift, and how strategically caching various values and objects can have a big impact on the overall performance of an app.
This week, let’s take a look at convenient, but sometimes divisive language feature — computed properties — and how they can let us build really elegant convenience APIs, how to avoid accidentally hiding performance problems when deploying them, and a few different strategies for picking between a computed property and a method.
Deploying generics in a more gentle fashion — to make a code base simpler, not more complicated.
Even though most of our classes, structs, and other types might have initially been created to solve a very specific problem — over time, we quite often find ourselves wanting to use a highly similar version of that same type or logic, but for something entirely different. This week, let’s take a look at a technique for making that happen — that involves making certain types increasingly configurable.
Michael Ilseman, developer on the Swift team at Apple, joins John to go on a deep dive into the String type, its implementation, and its related APIs. Topics range from the way Swift’s String API is designed, to its underlying complexities, and practical performance tips.
Everyone is an API designer. While it’s easy to think of APIs as something that’s only relevant for SDKs or frameworks, it turns out that all app developers design APIs almost every single day. This week, let’s take a look at a number of tips and techniques that can be good to keep in mind when designing various APIs in Swift.
A DSL, short for Domain Specific Language, can be explained as a special kind of API that focuses on providing a simple syntax that's tailored to working within a specific domain. Swift's type inference and overloading capabilities also make it a really great language to build DSLs in - and this week, let's do just that.
How API design isn’t only something to consider when building frameworks and SDKs, but how it also can be a fantastic tool to improve the architecture of apps.
Swift’s @autoclosure attribute enables us to define an argument that automatically gets wrapped in a closure. It’s primarily used to defer execution of a (potentially expensive) expression to when it’s actually needed, rather than doing it directly when the argument is passed.
I’d like to share a technique that I’ve come to find quite useful when using Swift’s do, try, catch error handling model — to limit the amount of errors that can be thrown from a given API call.