简体   繁体   English

Swift:在applicationWillTerminate之后获取persistentStoreCoordinator时核心数据崩溃

[英]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. 新版本中增加了一个新功能,我们为此功能添加了新的coredata表。

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). 首先,您应该发布错误代码,例如AppDelegate中的getter(行号,请参见堆栈跟踪)。

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). 通常,等到应用程序终止后可能要花费很长的时间(因为我认为iOS 4试图使它们保持活动状态)。 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. 您可以将逻辑转移到applicationDidEnterBackground ,但是我认为这也容易出错,因为如果应用程序崩溃则不会调用该方法。

You should save the context as often as possible (but not more often :-), eg every time a view controller gets dismissed or so. 您应该尽可能频繁地保存上下文(但不要更频繁地保存:-),例如,每次关闭视图控制器时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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