Urgent.News

What's breaking now, across thousands of outlets.

Tech

Swift 6 Gave Me Zero Warnings, but Two Objective-C Callbacks Still Crashed at Runtime

How two Objective-C callbacks triggered Swift 6 actor-isolation crashes despite zero compiler warnings, and how the bugs were reproduced and fixed.

Swift 6 Gave Me Zero Warnings, but Two Objective-C Callbacks Still Crashed at Runtime

Three separate crash reports came from a Swift 6 app named Amana over a three-day period. All three crashes were identical, with the same "EXC_BREAKPOINT (SIGTRAP)" error occurring on the "com.apple.BGTaskScheduler" queue. The app, built with Swift 6 language mode, uses a BGTaskScheduler to perform background tasks, but the crash was unrelated to warnings from the compiler.

The background task was registered using BGTaskScheduler.shared.register(forTaskWithIdentifier:using:), which by default uses a background queue. However, the closure handling the task was declared with @MainActor, causing the Swift runtime to check if the task was running on the main actor's executor. Since the task was running on a different queue, the check failed, resulting in the crash.

To fix the issue, the BGTaskScheduler's using parameter was changed to .main, matching the declaration of the closure. This ensured the task was executed on the correct queue and the crash was resolved. The same issue was later encountered with Apple's PhotoKit, where a closure inside a @MainActor method led to a crash when running on the "com.apple.PHPhotoLibrary.changes" queue. By moving the closure out of the actor, the crash was eliminated.

Written by urgent.news from HackerNoon's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at hackernoon.com →

More in Tech

More from Tuesday 22 September →