Result builders in Swift explained with code examples
Feb 9, 2021, 4:34 AM
Result builders in Swift allow you to build up a result using ‘build blocks’ lined up after each other. They were introduced in Swift 5.4 and are available in Xcode 12.5 and up. Formerly known as function builders, you’ve...
XCTExpectFailure: Expected test failures explained with code examples
Feb 2, 2021, 3:56 AM
XCTExpectFailure was introduced in Xcode 12.5 and allows marking test failures as expected. The first time I read about this new API I was kind of confused: why wouldn’t we use methods like XCTAssertThrowsError instead? I continued...
Lazy var in Swift explained with code examples
Jan 25, 2021, 11:36 AM
A lazy var is a property whose initial value is not calculated until the first time it’s called. It’s part of a family of properties in which we have constant properties, computed properties, and mutable properties. A lazy...
Closures in Swift explained with Code Examples
Jan 19, 2021, 4:48 AM
Closures in Swift can be challenging to understand with types like trailing closures, capturing lists, and shorthand syntaxes. They’re used throughout the standard library and are part of the basics you need to know when writing...
What is a Computed Property in Swift?
Jan 12, 2021, 3:44 AM
Computed properties are part of a family of property types in Swift. Stored properties are the most common which save and return a stored value whereas computed ones are a bit different. A computed property, it’s all in the name,...
SwiftLee 2020 In Review: Most read blog posts
Jan 5, 2021, 4:25 AM
Every year I’m looking back at what I achieved with SwiftLee as well as what I want to achieve in the upcoming year. I did this in 2018, 2019, and I’m doing the same in this blog post for 2020. 2020 is definitely not comparable...
Getting started with UIKit in SwiftUI and vice versa
Dec 28, 2020, 3:00 AM
SwiftUI can work together with UIKit by making it easier to add SwiftUI views to UIKit and visa versa using a few extensions shared in this blog post. SwiftUI was introduced in iOS 13 at a time many of us have a big app built with UIKit....
Getting started with associated types in Swift Protocols
Dec 22, 2020, 3:38 AM
Associated types in Swift work closely together with protocols. You can literally see them as an associated type of a protocol: they are family from the moment you put them together. Obviously, it’s a bit more complicated to explain...
Result in Swift: Getting started with Code Examples
Dec 15, 2020, 5:02 AM
The Result enum is available since Swift 5 and allows us to define a success and failure case. The type is useful for defining the result of a failable operation in which we want to define both the value and error output type. The standard...
Xcode Mark Line to improve readability using // Mark: comments
Dec 8, 2020, 5:21 AM
Xcode Mark Lines allows us to create a better overview of sections within our classes or structs. A so-called mark comment adds both a chapter title and linebreak in the Xcode method navigator. This chapter split makes it easier to quickly...
App Launch Time: 7 tips to increase performance
Dec 1, 2020, 3:00 AM
App Launch Time is the time it takes before your app becomes responsive after startup. As the first experience of your user it’s important that it’s smooth and as fast as possible. A slow startup time could mean losing a lot of...
Getting started with Property Wrappers in Swift
Nov 24, 2020, 2:00 AM
Property Wrappers in Swift allow you to extract common logic in a distinct wrapper object. Since the introduction during WWDC 2019 and becoming available in Xcode 11 with Swift 5 there have been many examples shared across the community....
Build performance analysis for speeding up Xcode builds
Nov 17, 2020, 3:00 AM
Build performance can be analysed in Xcode to speed up Xcode builds. This can easily speed up your workflow and save a lot of time during the day. Slow builds tempt to distract us as we have to wait and jump on distractions like Twitter...
Data validation on insertion, update, and deletion in Core Data
Nov 10, 2020, 2:58 AM
Data validation in apps is important to make sure we save data conforming to the business rules. A name should be of a certain length and can’t contain invalid characters. It’s tempting to write all this logic in a new...
Derived Attributes to improve Core Data Fetch Performance
Nov 3, 2020, 4:25 AM
Derived attributes are available since iOS 13 and aim to improve fetch performance in many different scenarios. Although we have great performance with the latest devices it’s good to be prepared for scaling up to fetching a large...
Constraints in Core Data Entities explained
Oct 27, 2020, 3:00 AM
Constraints in Core Data are part of an entity configuration. Settings like the entity name and Spotlight display name might be easy to understand while constraints are a bit less known. However, they can be super useful to maintain a...
NSManagedObject events: handling state in Core Data
Oct 20, 2020, 2:35 AM
An NSManagedObject lifecycle goes from insertion and updates until deletion in the end. All those events come with their own common related modifications and can be used in many different ways. Managing state in Core Data from within the...
How to use the #available attribute in Swift
Oct 13, 2020, 3:00 AM
Marking pieces of code as available per platform or version is required in the ever changing landscape of app development. When a new Swift version or platform version arrives, we’d like to adopt to it as soon as possible. Without...
Try Catch Throw: Error Handling in Swift with Code Examples
Oct 5, 2020, 3:00 AM
Try catch in Swift combined with throwing errors make it possible to nicely handle any failures in your code. A method can be defined as throwing which basically means that if anything goes wrong, it can throw an error. To catch this...
Overriding UserDefaults for improved productivity
Sep 29, 2020, 3:00 AM
UserDefaults within apps are used to store data related to user configurations. It’s an easily accessible data store for saving states, statistics, and other app-related data. Launch arguments are passed to the application on launch...
How-to use Diffable Data Sources with Core Data
Sep 22, 2020, 3:45 AM
Diffable Data Sources were introduced at WWDC 2019 as a replacement for UICollectionViewDataSource and UITableViewDataSource. The API is available on iOS 13 and up and makes it easy to set up lists of data in which changes are managed...
Diffable Data Sources Adoption with Ease
Sep 15, 2020, 3:00 AM
Diffable Data Sources were introduced at WWDC 2019 and are available since iOS 13. They’re a replacement of the good old UICollectionViewDataSource and UITableViewDataSource protocols and make it easier to migrate changes in your...
Persistent History Tracking in Core Data
Sep 8, 2020, 3:00 AM
WWDC 2017 introduced a new concept available from iOS 11 which is persistent history tracking. It’s Apple’s answer for merging changes that come from several targets like app extensions. Whenever you change something in your...
withAnimation completion callback with animatable modifiers
Sep 1, 2020, 3:00 AM
SwiftUI is great when it comes down to animations as it does a lot for you with methods like withAnimation and animation(...). You can simply pass in the things you’d like it to animate and SwiftUI will make sure your views move...
Write-Ahead Logging (WAL) disabled to force commits in Core Data
Aug 25, 2020, 9:51 AM
Write-Ahead Logging is the default journaling mode for Core Data SQLite stores since iOS 7 and OS X Mavericks. Journaling in Core Data is best explained as the way data transactions are saved into the underlying SQLite store. The WAL mode...
How to combine text weights in SwiftUI
Aug 18, 2020, 3:00 AM
Combining multiple text weights in SwiftUI might not look straight forward at first. If you’re used to using UIKit you were probably looking into support for NSAttributedString in which you could apply different text styles for...
Adding a closure as a target to UIButton and other controls in Swift
Aug 5, 2020, 1:15 PM
The target-action pattern is used in combination with user interface controls as a callback to a user event. Whenever a button is pressed on a target, its action will be called. The fact that the method is not defined close to the control...
Launch screens in Xcode: All the options explained
Jul 28, 2020, 3:00 AM
Launch screens appear when your app starts up and give the user the impression that your app is fast and responsive. After your app is loaded it will be replaced with your app’s first screen after which the user can start using your...
OSLog and Unified logging as recommended by Apple
Jul 20, 2020, 1:30 AM
OSLog as a replacement of print and NSLog is the recommended way of logging by Apple. It’s a bit harder to write, but it comes with some nice advantages compared to it’s better-known friends. By writing a small extension you...
ValueTransformer in Core Data explained: Storing absolute URLs
Jul 14, 2020, 3:00 AM
ValueTransformers in Core Data are a powerful way of transforming values before they get inserted into the database and before they get read. They’re set up in an abstract class which handles the value transformations from one...
Full-screen development with Xcode and the Simulator
Jul 7, 2020, 3:00 AM
While developing apps it’s important to create focus to get in your flow and speed up development. Full-screen mode can help to keep your focus without any distraction from other apps. Up until Xcode 12 full-screen support was hidden...
SVG Assets in Xcode for Single Scale Images
Jun 30, 2020, 3:00 AM
Xcode 12 introduced support for using Scalable Vector Graphic (SVG) image assets in iOS, macOS, and iPadOS. It’s one of those changes that you might have missed during WWDC 2020 as it’s quite a small addition. Up until Xcode...