Combine debugging using operators in Swift

Combine debugging can be hard with long stack traces which don’t help at all. Asynchronous callbacks follow up on each other rapidly and easily make it hard to find the root cause of an issue. It’s next to the big learning curve one of the most common reasons to not go for reactive programming in … 

 

Creating a custom Combine Publisher to extend UIKit

A Custom Combine Publisher can add missing functionalities to UIKit elements you use every day. A lot of boilerplate code can be removed and implementations can be simplified. A simple example is responding to UIControl events. The standard library comes with a few great extensions to, for example, decode JSON easily and assign values to key … 

 

Getting started with the Combine framework in Swift

Combine is a new framework by Apple introduced at WWDC 2019. The framework provides a declarative Swift API for processing values over time. In other words, as described by Apple itself: Customize handling of asynchronous events by combining event-processing operators. At first, this might sound quite overwhelming. What does it actually mean? What can I … 

 

Dynamic Member Lookup combined with key paths in Swift

Dynamic member lookup has been introduced in Swift 4.2 with SE-195 and already allowed some pretty nice solutions to for example implement JSON parsing. Just like the @propertyWrapper keyword as discussed in last weeks blog post, it can be used with a @ keyword: @dynamicMemberLookup. As quoted from the proposal, dynamic member lookup has been added … 

 

Property wrappers to remove boilerplate code in Swift

Property wrappers were first introduced during WWDC 2019 and come with Xcode 11 in Swift 5. It’s a neat addition to the Swift library and allows us to remove a lot of boilerplate code which we probably all have written in our projects. A background story on property wrappers can be found on the Swift … 

 

Try catch throw: implementing Error Handling in Swift

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 statement. Creating a throwing method … 

 

Using NSBatchDeleteRequest to delete batches in Core Data

An NSBatchDeleteRequest can be used to efficiently delete a batch of entries from a Core Data SQLite persistent store. It runs faster than deleting Core Data entities yourself on a managed object context as they operate at the SQL level in the persistent store itself. Its usage, however, is a bit less simple compared to the … 

 

Weak self and unowned self explained in Swift

Weak self and unowned self in Swift for many of us are hard to understand. Although Automatic Reference Counting (ARC) solved a lot for us already, we still need to manage references when we’re not working with value types. By adding weak by default you probably end up working with optionals in a lot of … 

 

Self-documenting code to improve readability in Swift

Self-documenting code can improve the readability of your codebase. It basically means that you don’t have to write comments to explain what your code is doing. Its advantages can be listed as followed Improved readability of your codebase Code is easier to understand Forces to think of single responsibility With a few basic tips, it’s …