TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

App sometimes crashes on launch since Monterey

Forums > macOS

Hello, I've got a strange problem with a published app since Monterey came out that I've only noticed now. The app basically crashes right after launching but not quite all of the time, just most of the time; the icon doesn't even have time to fully appear when it does crash.

If the app hasn't been opened in a while it seems to launch correctly most of the time though. Additionally, as strange as it sounds, it is much more likely to launch correctly if you open the app from the Launchpad rather than the finder.

The error messages I get from Xcode when I launch from there is:

_TSGetMainThread_block_invoke:Main thread potentially initialized incorrectly, cf rdar://problem/67741850

Unable to load nib file: Main, exiting

Has anyone else seen anything like this? The app uses Core Data with CloudKit.


Having the same issue here, did you get anywhere? Also using Core Data with CloudKit.


I've encountered the same issue in a SwiftUI macOS app, also using Core Data and CloudKit. My NSPersistentCloudKitContainer got initialised right when my App subclass got initialised. I figured that might be the cause. I've changed that to a lazy var and haven't seen the issue since. Hope that helps!


I hit the same issue again half a year later. I had added code which accessed the persistent container right on app start-up again, resulting in the same crash. This time wrapping those calls in DispatchQueue.main.async { ... } did the trick. Alternatively, calling out to let _ = NSApplication.shared in my App.init() method also does the trick. I've filed this as FB10902789.


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.