Swift
Learn more and get better in Swift using this list of Swift blog posts, tutorials, tips, and tricks.
Try Catch Throw: Error Handling in Swift with Code Examples
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 error, we need to implement a so-called do-catch ...
How-to use Diffable Data Sources with Core Data
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 through so-called snapshots. The Core Data team added new delegate methods ...
Diffable Data Sources Adoption with Ease
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 data views. Diffable Data Sources come with a few benefits over using the classic data source ...
Persistent History Tracking in Core Data
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 Core Data database from your Share Extension, a transaction is written which can be merged ...
Write-Ahead Logging (WAL) disabled to force commits in Core Data
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 is significantly faster in most scenarios compared to the ...
Adding a closure as a target to UIButton and other controls in Swift
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 ...
ValueTransformer in Core Data explained: Storing absolute URLs
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 representation to another. They're often used as a way to store values that ...
SF Symbols: The benefits and how to use them guide
SF Symbols were introduced during WWDC 2019 and are a big present for us developers. Apple basically gave us free symbols to use in our app, and it's straightforward to use them as well! With SF Symbols 2.0 being introduced in WWDC 2020 and 3.0 at WWDC 2021, we've got ...
@discardableResult in Swift explained: Ignoring return values
While writing methods in Swift you're often running into scenarios in which you sometimes want to ignore the return value while in other cases you want to know the return value. The @discardableResult attribute allows us to enable both cases without having to deal with annoying warnings or underscore replacements ...
Core Data Performance: 6 tips you should know
Writing Core Data code with performance in mind helps to prepare your app for the future. Your database might be small in the beginning but can easily grow, resulting in slow queries and decreased experience for the user. Since I started writing the Collect by WeTransfer app in 2017 I've ...
Expressible literals in Swift explained by 3 useful examples
Expressible literals allow you to initialize types by making use of literals. There are multiple protocols available in the Swift standard library and chances are big that you've already been using one of those. An example is the ExpressibleByStringLiteral allowing us to initialize a String using surrounding double quotes instead ...
String Interpolation in Swift explained using 4 useful cases
Swift 5 introduced a decent version of string interpolation with SE-228 and updated the old version of the ExpressibleByStringInterpolation protocol that has been deprecated since Swift 3. The new version of this protocol allows us to write powerful extensions to existing types that define how objects interact when used within ...