SwiftUI CloudKit App crashes at start with "Unable to load nib file: MyApp, exiting"

I'm developing a SwiftUI App for macOS in Xcode 13.2.

When I try to run the App in Xcode, I get this error messages in the console and the app terminates:

2021-12-28 13:13:21.680087+0100 MyAppProject[21343:363165] [CK] Giving up waiting to register for remote notifications

2021-12-28 13:13:23.548389+0100 MyAppProject[21343:362383] Unable to load nib file: MyAppStartViewName, exiting

Until now, the error happend sporadically. Now I use a new MacBookPro with M1max and the error happens every time. As it is a SwiftUI App, there is no nib file at all. I didn't find any information about SwiftUI generating a nib file...

How can I prevent the bug and get the App running? Any hints are welcome :-)

Accepted Reply

I found the problem :-)

During the initialization of the model of the @main view I did some longer running tasks to initialize some background processes. Now I run them on a background task using perform{} and the bug is gone.

The reason why the bug appeared on my new, faster hardware obviously was the addition of more data structures to be initialized, so it took longer.

Replies

I found the problem :-)

During the initialization of the model of the @main view I did some longer running tasks to initialize some background processes. Now I run them on a background task using perform{} and the bug is gone.

The reason why the bug appeared on my new, faster hardware obviously was the addition of more data structures to be initialized, so it took longer.

Unfortunately the problem was NOT solved... I've got the problem again and it happens most of the time on my 2021 MacBook Pro (M1 Max) and not so often on my 2020 MacBook Pro (M1). So it looks like a timing problem...

Post not yet marked as solved Up vote reply of h725 Down vote reply of h725

It seems like now I have found the real reason for this strange behaviour...

My App was a AppKit application before the migration to SwiftUI.

After some searching in the project settings I found under the macOS build target in "Info / Custom macOS Application Target Properties" the key "Main nib file base name" which contained "MyApp.nib". It looks like sometimes during the start of the App this file was searched and not found and sometimes maybe the start of the App was faster so it was not searched for... However: After deleting the value, the error didn't reappear. Let's hope this is the final solution...

Post not yet marked as solved Up vote reply of h725 Down vote reply of h725