简体   繁体   中英

Swift : core data crashed when getting persistentStoreCoordinator after applicationWillTerminate

We updated our app to a new version.

There was a new function added to the new version and we added a new coredata table for that function.

After app was released, an error continued without no answer. Would somebody met the same error or same problem and solved this error?

Thread 0 Crashed:
0   libsystem_kernel.dylib              0x000000018981f014 __pthread_kill + 8
1   libsystem_c.dylib                   0x0000000189793400 abort + 140
2   [AppName]                           0x00000001002d0c58 AppDelegate.(persistentStoreCoordinator.getter).(closure #1) (AppDelegate.swift:318)
3   [AppName]                           0x00000001002c7dec AppDelegate.persistentStoreCoordinator.getter (AppDelegate.swift:334)
4   [AppName]                           0x00000001002d0cbc AppDelegate.(managedObjectContext.getter).(closure #1) (AppDelegate.swift:338)
5   [AppName]                           0x00000001002c8054 AppDelegate.managedObjectContext.getter (AppDelegate.swift:342)
6   [AppName]                           0x00000001002c8198 AppDelegate.saveContext() (AppDelegate.swift:347)
7   [AppName]                           0x00000001002c7780 AppDelegate.applicationWillTerminate() (AppDelegate.swift:295)
8   [AppName]                           0x00000001002c77d8 @objc AppDelegate.applicationWillTerminate() (AppDelegate.swift:0)
9   UIKit                               0x0000000190792704 <redacted> + 244
10  UIKit                               0x00000001909947cc <redacted> + 792
11  UIKit                               0x0000000190997fdc <redacted> + 292
12  UIKit                               0x0000000190989d50 <redacted> + 560
13  UIKit                               0x00000001906f90b4 <redacted> + 168
14  CoreFoundation                      0x000000018a7fe0c0 <redacted> + 32
15  CoreFoundation                      0x000000018a7fbcf0 <redacted> + 372
16  CoreFoundation                      0x000000018a7fc180 <redacted> + 1024
17  CoreFoundation                      0x000000018a72a2b8 CFRunLoopRunSpecific + 444
18  GraphicsServices                    0x000000018c1de198 GSEventRunModal + 180
19  UIKit                               0x00000001907717fc <redacted> + 684
20  UIKit                               0x000000019076c534 UIApplicationMain + 208
21  [AppName]                           0x00000001002d1a94 main (AppDelegate.swift:17)
22  ???                                 0x000000018970d5b8 0x0 + 0

First, you should post the erronious code, eg the getters in the AppDelegate (line numbers see stack trace).

In general, waiting until the application is terminated can take a very long time (because iOS tries to keep them alive, since iOS 4 i think). You could tranfer the logic into applicationDidEnterBackground , but I think this is also error prone because this will not be called if the app crashes somehow.

You should save the context as often as possible (but not more often :-), eg every time a view controller gets dismissed or so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM