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 and can be used to alter the application for debugging purposes. It’s often used by Apple to allow developers to enable specific debugging modes, like in Core Data. We can do the same ourselves to enable certain debug modes in our apps.
A common use case for using launch arguments is to force enable an introduction screen during development. …
Diffable data sources were introduced at WWDC 2019 as a replacement for
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 through so-called snapshots.
The Core Data team added new delegate methods to the
NSFetchedResultsControllerDelegate to make it easier to work with diffable data sources in Core Data. However, it turns out that it's very easy to make mistakes that can result in bad performance. I did not give up and managed to make Core Data work nicely together with diffable data sources. …
Diffable data sources were introduced at WWDC 2019 and have been available since iOS 13. They’re a replacement for the good old
UITableViewDataSource protocols and make it easier to migrate changes in your data views.
Diffable data sources come with a few benefits over using the classic data source approach and are the preferred way nowadays to work with collection and table views. However, it might not always be easy to rewrite existing code that is heavily integrated into using the old approach. …
WWDC 2017 introduced a new concept available from iOS 11: 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 Core Data database from your Share Extension, a transaction is written that can be merged into any of your other targets.
You might have read my article Core Data and App extensions: Sharing a single database that suggests Darwin notifications share a database between app extensions. This has been a great solution and still works, but it isn’t recommended as a solution by Apple and uses undocumented Darwin notifications. …
SwiftUI is great when it comes down to animations, as it does a lot for you with methods like
animation(...). You can simply pass in the things you'd like it to animate and SwiftUI will make sure your views move smoothly from one state to another.
Sometimes, however, you’d like to have the same functionality as you’re used to from UIKit that allows you to update the state after an animation completes. When you’re looking for ways to get a callback once an animation completes, you’ll realize that it’s not that simple. …
Write-Ahead Logging has been 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 is significantly faster in most scenarios compared to the previous default “rollback” journal mode and is the underlying reason that makes it possible to have concurrency in Core Data.
With the WAL mode, Core Data keeps the main SQLite store file untouched and keeps track of data transactions in a
-wal file within the same location of the SQLite store. This means that in some cases, changes are not yet visible in the SQLite store itself. Because of this, you might want to force commit those changes into the SQLite store. …
Combining multiple text weights in SwiftUI might not look straightforward 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 certain ranges.
SwiftUI makes it possible to combine different text styles with the built-in plus (+) operator implementation. Multiple text views are combined into one and wrap nicely if used correctly.
Before we dive into the solution that worked best in my case, I’d like to go over a few oft-suggested solutions on forums like Stack Overflow.
You could see combining multiple weights in a single text view as displaying multiple keywords in a grid kind of view. Searching for a solution might bring you to this page, which tells you to use a
GeometryReader combined with custom alignment guides to mimic text wrapping. …
SwiftUI was introduced in iOS 13 at a time when many of us have a big app built with UIKit. SwiftUI makes us enthusiastic to get started with this new framework for building apps, just like when Swift was first introduced.
When Swift was introduced we had to migrate from Objective-C to Swift. Many apps are probably still using (partly) Objective-C, as that transition can take quite some time. It’s good to know how to start the transition to make this process as short as possible. iOS 14 is getting close and you might consider dropping iOS 12 later this year, allowing you to write new views in SwiftUI. …
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 definition is sometimes seen as a downside and reason for a lot of us developers to search for closure-based solutions on sites like Stack Overflow.
The iOS 14 SDK introduced new APIs that allow us to use UIControls in combination with closures. Common
UIControl elements are
UISwitch, but there are a lot more that all inherit from the
UIControl object. …
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, the launch screen will be replaced with your app’s first screen at which point the user can start using your app.
Xcode creates a storyboard by default that you can use to set up your loading screen. Although this works fine in most cases, there are exciting new options available in Xcode 12 and iOS 14.
But before we dive in, let’s see how we all started implementing this back in the day.
Launch screens have quite some history. Up until Xcode 6, the only option we had was providing static images inside an asset catalog. This was already better than before, as we used to set specific file names for those images to show up. …