Swift 6 suitable notification observers in iOS
I have a couple of side projects going on, although it is always a challenge to find time of them. One of them, SignalPath, is what I created back in 2015. Currently, I have been spending some time to...
View ArticleAnyClass protocol and Objective-C methods
AnyClass is a protocol all classes conform to and it comes with a feature I was not aware of. But first, how to I ended up with using AnyClass. While working on code using CoreData, I needed a way to...
View ArticleAnyView is everywhere in Xcode 16
Loved to see this entry in Xcode 16’s release notes: Xcode 16 brings a new execution engine for Previews that supports a larger range of projects and configurations. Now with shared build products...
View ArticleSorting arrays in Swift: multi-criteria
Swift’s foundation library provides a sorted(by:) function for sorting arrays. The areInIncreasingOrder closure needs to return true if the closure’s arguments are increasing, false otherwise. How to...
View ArticleHow to keep Date’s microseconds precision in Swift
DateFormatter is used for converting string representation of date and time to a Date type and visa-versa. Something to be aware of is that the conversion loses microseconds precision. This is...
View ArticleWrapping async-await with a completion handler in Swift
It is not often when we need to wrap an async function with a completion handler. Typically, the reverse is what happens. This need can happen in codebases where the public interface can’t change just...
View ArticleDark Augmented Code theme for Xcode
After a couple of years, I tend to get tired of looking at the same colour scheme in Xcode. Then I spend quite a bit of time looking for a new theme and then coming back with empty hands. Material...
View ArticleCancellable withObservationTracking in Swift
Observation framework came out along with iOS 17 in 2023. Using this framework, we can make objects observable very easily. Please refer to @Observable macro in SwiftUI for quick recap if needed. It...
View ArticleReferencing itself in a struct in Swift
It took a long time, I mean years, but it finally happened. I stumbled on a struct which had a property of the same type. .gist table { margin-bottom: 0; } This file contains bidirectional Unicode...
View ArticleScrollView phase changes on iOS 18
In addition to scroll related view modifiers covered in the previous blog post, there is another one for detecting scroll view phases aka the state of the scrolling. The new view modifier is called...
View ArticleScroll geometry and position view modifiers in SwiftUI on iOS 18
WWDC’24 brought some updates to scrolling. One of which is onScrollGeometryChange(for:of:action:) what we can use for reacting to scroll geometry changes. The view modifier has two closures, where the...
View ArticleZoom navigation transition in SwiftUI
WWDC’24 brought a lot of new and SwiftUI received many updates. One of which, is the new NavigationTransition protocol and the zoom transition. And that is pretty much what it contains at the moment....
View ArticleAligning views in different stacks in SwiftUI
While working on a SwiftUI view, I needed a way for aligning views in different stacks in a way that they are centred. Most of the time I can get away using default alignment values, what HStack and...
View ArticleTask with @MainActor gotcha in Swift
While working on a codebase with a mix of structured concurrency and good old DispatchQueues I stumbled on something. Most of the time this would not be a problem, but in my case, it was important...
View ArticleLLDB print commands for debugging in Xcode
Whoever has used Xcode for debugging has heard about the po command. This command is used for printing object descriptions. Whatever we write after po gets compiled into actual code and is executed in...
View ArticleInitializing @MainActor type from a non-isolated context in Swift
Recently I was in the middle of working on code where I wanted a type to require @MainActor since the type was an ObservaleObject and makes sense if it always publishes changes on the MainActor. The...
View ArticleGetting started with Benchmark package
There was a blog post on swift.org about a new Swift package called Benchmark at the end of the March. As the name speaks for itself, it is all about measuring the performance of the piece of a code....
View ArticleMerging sorted arrays with duplicates in Swift
The other day, I needed a way for merging sorted arrays containing structs. In addition, not just merging arrays, I also needed to handle duplicates. The duplicate handling needed to prioritize...
View ArticleCollection with opaque base collection in Swift
The other day I had an interesting small problem to solve. How to create a custom collection type which could have other kinds of collections as a base collection. The use-case for the collection is...
View ArticlePerforming accessibility audits with UI tests on iOS
A new way how to test your app’s accessibility was added in iOS 17. XCUIApplication has a new method, performAccessibilityAudit. It has two arguments where the first is audit types which is by default...
View Article