The @preconcurrency attribute is part of the tools that help you incrementally migrate to strict concurrency checking. When async/await was introduced by Apple, we were writing non-structured asynchronous code, mainly using closures. On our road to Swift 6, we must prepare our projects for strict concurrency checks done by the compiler. The SE-0337 proposal makes …
Swift
OptionSet in Swift explained with code examples
OptionSet in Swift allows you to define a set of options for configurations. It’s the Swift variant of the well-known NS_OPTIONS in Objective-C and it’s used throughout the standard libraries. A set of options is often confused by a set of enum cases, but they’re not the same. While you could create a similar solution …
App Launch Time: 7 tips to increase performance
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 users which can result in less usage in your app. Even-though today’s devices …
Measure the performance of code in Swift
It’s important in any type of programming language to know how to measure the performance of code as there are many different ways to write solutions and not every solution is as performant as the other. If a piece of code turns out to be slow in, for example, the results of the Time Profiler …
Updating to Swift 4.2
Swift 4.2 is a major release and shipped with Xcode 10. It comes with a lot of code improvements for which the best way to start is to watch the WWDC 2018: What’s New in Swift session. Some of the improvements are easy to implement in your existing code. Replace strongSelf with self SE-0079 makes …
Defer usage in Swift
Although the defer keyword was already introduced in Swift 2.0, it’s still quite uncommon to use it in projects. Its usage can be hard to understand, but using it can improve your code a lot in some places. The most common use case seen around is opening and closing a context within a scope How …
Compiler Diagnostic Directives using a hashtag in Swift
The Swift standard library brings quite some compiler diagnostic directives by default. Although this might not ring a bell at all, a lot of them are quite known and listed in the Swift repository. Warning Warning can be used to manually trigger a warning on the given line. This can be useful during development to …
Where usage in Swift
Where is a powerful keyword within Swift to easily filter out values. It can be used in many different variants from which most of them are listed in this post. Usage in a switch Consider having the following enum: Using where you can easily filter the case for a specific age range: Usage in a …
Controlling Progress children by adding remove
Controlling Progress children by default makes it only easy to add children to a Progress instance, but removing is not possible by default. This could have been useful when you want to use a single Progress instance which can have different children over time. Using a custom class MutableProgress makes this possible. Controlling Progress children …
Updating to Swift 4.1
Swift 4.1 is released on the 29th of March and will be shipped with Xcode 9.3. Although it’s a minor language release, it did bring some improvements. How to get started? First of all, Swift 4.1 is source compatible with Swift 4.0. So no need to rush! Before you start, get yourself up to date …