Applying rounded corners to a UIKit or SwiftUI view
How to round the corners of a UIKit or SwiftUI view in various ways.
Articles, podcasts and news about Swift development, by John Sundell.
Frequently published articles about Swift techniques, language features, architectual patterns, and beyond.
How to round the corners of a UIKit or SwiftUI view in various ways.
How to validate email addresses in Swift using a dedicated RawRepresentable type and Foundation’s NSDataDetector API.
How key paths can be made much more powerful when used to query and filter collections.
How a SwiftUI view’s body can be split up into multiple computed properties, which is a great alternative to using separate types in certain situations.
Lightweight state observations.
A neat technique for values that can’t be created with a single line of code.
Using a dedicated protocol to make it easy to define new containers.
Combining dynamic and constant output values.
How Swift 5.3 lets us combine lazy properties with willSet and didSet observers.
Why rewrite views when we can reuse them?
A new addition to UIKit in iOS 14.
A tip for more dynamic navigation.
With or without storyboards.
And how that can be customized.
A few features that make Swift’s multiline string literals really useful.
Really useful for utility methods.
Useful for both apps and widgets.
Specializing container views.
A nice new feature that’s especially useful within SwiftUI views.
Another useful interoperability API.
How SwiftUI’s new StateObject property wrapper works, and how it compares to ObservedObject.
Several ways of defining default values for initializers and functions.
Testable code without any protocols.
Making it easy to observe a single value in a read-only fashion.
Adding more contextual information to test failures.
Sometimes, we’re able to omit certain generic type constraints.
Defining Swift enums based on completely custom types.
Dynamic properties with type safety.
How to observe iOS 13.4’s new granular keyboard events.
Making wrapping views a lot easier.
Different ways of helping the compiler type-check generic code.
Implementing a property wrapper to enable certain properties to be overridden only in debug mode.
A look at the standard library’s Result type, what kind of situations that it might be useful in, and tips and tricks that can be good to keep in mind when working with it.
How Swift’s memberwise initializers work, and when those initializers can be used.
How the standard library enables us to add randomness to our code.
Transforming strings, integers, and other raw values into SwiftUI views.
Various ways of conditionally creating SwiftUI views that depend on optional values.
A few tips on deciding how to implement each given iteration.
Making extensions on generic types more compact.
How enums work in Swift, a look at some of their most prominent features, and examples of situations in which they can be incredibly useful.
In Swift, it’s possible to satisfy a throwing function protocol requirement using a non-throwing function, which can be very useful in certain situations.
How to enable a type to be expressed by strings that contain interpolated values.
A look at a few different ways that closures can be defined and used in Swift, the flexibility of Swift’s closure syntax, and how behaviors like escaping and capturing may impact our code.
How to enable and use test coverage in Xcode.
A recap of the basics of SwiftUI, Apple’s declarative new UI framework for building apps across all of their platforms. How to build custom views and modify existing ones, how to manage local state within a view, and how to compose multiple views to form new ones.
One way of transforming values in Swift is by mapping a collection into an array of new values, using a transform. The Swift standard library offers three main APIs for that kind of mapping — map, flatMap and compactMap. Let’s take a look at how they work.
Swift enables us to create generic types, protocols, and functions, that aren’t tied to any specific concrete type — but can instead be used with any type that meets a given set of requirements. Let’s take a look at how generics work in Swift, and how to create our own.
Just like modern versions of Objective-C, Swift uses the ARC (Automatic Reference Counting) memory management model. Let’s take a look at how ARC works, and how to avoid common memory-related issues, such as retain cycles.
How an application deals with errors and unexpected values is arguably just as important as how it deals with valid results. Let’s take a look at a few key techniques that can help us provide a better user experience whenever an error was encountered within our code.
Adding animations to an app can be a great way to both delight users, and to draw their attention to certain information or actions, through motion. When deployed in the right places, animations can really make an app appear more polished and easy to use. Let’s take a look at how to get started.
Introduced in Swift 4, the Codable API enables us to leverage the compiler in order to generate much of the code needed to encode and decode data to/from a serialized format, like JSON. Let’s take a look at how to use it.
Most apps these days need a way to download data from the Internet — whether that’s files, images, or by talking to some form of web API through a format like JSON. Let’s take a look at how to do that using Foundation’s URLSession API.
Using unit tests, and other forms of automated testing, can be a great way to protect a code base against regressions and reduce the need for manual testing. Let’s take a look at how to get started.
Just like how a UIView can be added to another UIView to form a hierarchy, a view controller can become the child of another view controller. Let’s take a look at how to do that.
Grand Central Dispatch is one of the few different options available to us when it comes to asynchronous programming in Swift. Let’s take a look at how it works and how to use it.
Auto Layout has undergone quite a lot of changes and improvements over the years, in particular with the introduction of layout anchors in iOS 9. Let’s take a look at how they work.
Let’s take a look at how the Swift 4.2 compiler is able to automatically synthesize conditional conformances to the Equatable and Hashable protocols.
In today's WWDC Update, let's take a look at how Core Animation this year has been made a bit more "Swifty", thanks to some better annotations and how many of its APIs that previously relied on strings now use synthesized enums and option sets.
In this first Daily WWDC Update we’ll try out an exciting new cross-platform framework called Natural Language. It provides a high-level API enabling easy access to a suite of language detection features when working with text in an app.
Assertions are not only an essential tool when writing tests - they're also super useful in order to write more predictable and easier to debug code. This week, let's look deeper into assertions, how they work, and how we can implement our own assert functions for performing various checks.
We often encounter situations in which we need to find a way to store objects based on some concept of identity. Whether it's in a cache, storing representations of objects on disk, or simply using a dictionary - we often need to find ways to uniquely identify the objects that we deal with. Let's take a look at a few such ways.
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.
Lazy properties allow you to create certain parts of a Swift type when needed, rather than doing it as part of its initialization process. This can be useful in order to avoid optionals, or to improve performance when certain properties might be expensive to create. This week, let’s take a look at a few ways to define lazy properties in Swift, and how different techniques are useful in different situations.
A lot of code that we write relies on the current date in some way. Let's take a look at how to test such code in a fast and predictable way, without having to invent a lot of infrastructure or resort to hacky solutions like swizzling the system date.
While Swift does not yet feature a dedicated namespace keyword, it does support nesting types within others. Let’s take a look at how using such nested types can help us improve the structure of our code.
Most apps written for any of Apple’s platforms rely on APIs that are singleton-based. From UIScreen to UIApplication to NSDate, static APIs are everywhere in Foundation, UIKit and AppKit. In this article I'll go through 3 steps to easily test code that uses such APIs.
Dependency injection is a great technique for decoupling code and making it easier to test. In this article, let’s take a look at how functions can be used for simple dependency injection.
How to use custom, lazily evaluated sequences in Swift to improve performance and enable you to deal with larger datasets, such as entries in a database.
How type erasure can be implemented using closures, and how it can help you work around using protocols with self or associated type requirements.
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.