簡體   English   中英

Swift:在applicationWillTerminate之后獲取persistentStoreCoordinator時核心數據崩潰

[英]Swift : core data crashed when getting persistentStoreCoordinator after applicationWillTerminate

我們已將應用程序更新為新版本。

新版本中增加了一個新功能,我們為此功能添加了新的coredata表。

應用發布后,錯誤繼續,沒有答案。 有人會遇到相同的錯誤或相同的問題並解決了該錯誤嗎?

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

首先,您應該發布錯誤代碼,例如AppDelegate中的getter(行號,請參見堆棧跟蹤)。

通常,等到應用程序終止后可能要花費很長的時間(因為我認為iOS 4試圖使它們保持活動狀態)。 您可以將邏輯轉移到applicationDidEnterBackground ,但是我認為這也容易出錯,因為如果應用程序崩潰則不會調用該方法。

您應該盡可能頻繁地保存上下文(但不要更頻繁地保存:-),例如,每次關閉視圖控制器時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM