One of the hottest topics right now in the iOS community is the new concurrency APIs introduced in Swift 5.5. I start refactoring some code that was using Combine Future with the new async/await
and I find a nice little trick that can help detect some problems while working with the new concurrency APIs.
Go to your project Build Settings, search for Other Swift Flags and add:
- -Xfrontend
- -warn-concurrency
- -Xfrontend
- -enable-actor-data-race-checks
Once done, build your project. If everything is fine, you shouldn’t get any errors, but if you did something wrong like not annotating a function or class as MainActor, you’ll get some errors like shown below:
The solution was to add the
@MainActor
annotation to the class and after that no more errors.