Swift
Learn more and get better in Swift using this list of Swift blog posts, tutorials, tips, and tricks.
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 ...
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 ...
CompactMap vs flatMap: The differences explained
CompactMap and flatMap, what are the differences and when do you use each? Swift 4.1 introduced this new method with the proposal 0187: Introduce Filtermap to gain more clarity in flatMap use cases. When to use compactMap Use this method to receive an array of nonoptional values when your transformation ...
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 ...
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: enum Action { case createUser(age: Int) case createPost case logout } ...
Typed notifications using custom extensions
The Swift API contains a lot of notifications sent out by the system like NSManagedObjectContextObjectsDidChange in Core Data or the AppDelegate events like UIApplicationDidBecomeActive. Some of these notifications contain rich data in their user info dictionary. Reading the user info data using typed notifications can clean up your code, especially ...
Printing data requests using a custom URLProtocol
Almost all apps contain some kind of data requests. Printing data requests could sometimes be handy for debugging purposes. This can be done fairly easy by using a custom URLProtocol. Creating a custom URLProtocol A custom URLProtocol is needed to print out the data requests. A custom implementation of URLProtocol ...
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 ...
Share Extension UI Tests written in Swift
UI Tests are a great tool to validate your application. It is easy to create them for your main application, but it might be harder to create a UI test for your share extension. This can be just as easy as your main application with some simple steps. UI Test ...
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, ...
Optional protocol methods in Swift
In Swift it's kind of unsupported to implemented optional protocol methods. You can, which is ugly, use the @objc syntax: @objc protocol MyProtocol { optional func doSomething(); } class MyClass : MyProtocol { // no error } Another disadvantage here is that structs are unsupported, as you're bridging for Objc ...
The start of a new blog
Hi there! After thinking a lot of starting my own blog, I've finally made the decision to create one! As iOS developer for my job I found myself experiencing a lot of problems, writing solutions and figuring out what's the best way to create this UI. Many times these are ...