我的應用程序正在生產中,並且在嘗試將festRequest的第一個元素轉換爲某個實體時,Crashlytics發生了一些崩潰。無論我多努力嘗試,我都無法重新創建這個崩潰。使用CoreData獲取時發生崩潰
static func getSettings() -> NotificationSettingsMO {
var settings: NotificationSettingsMO!
let moc = DataController.shared.managedObjectContext
moc.performAndWait {
do {
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "NotificationSettings")
settings = try moc.fetch(fetchRequest).first as! NotificationSettingsMO
} catch {
print(error)
}
}
return settings
的崩潰發生時試圖投請求NotificationSettingsMO的第一個元素,我敢肯定的實體存在,因爲我創造它是創建用戶時。這也只發生在一小部分用戶,但因爲它使應用程序崩潰,我想嘗試找出是什麼原因造成的。
編輯:我已經把它貼崩潰日誌
Crashed: com.apple.main-thread
0 MyApp 0x100073360 specialized static NotificationSettingsMO.(getSettings() -> NotificationSettingsMO).(closure #1) (NotificationSettingsMO.swift:25)
1 MyApp 0x10007309c partial apply for static NotificationSettingsMO.(getSettings() -> NotificationSettingsMO).(closure #1) (NotificationSettingsMO.swift)
2 CoreData 0x18311d08c developerSubmittedBlockToNSManagedObjectContextPerform + 196
3 CoreData 0x18311cf54 -[NSManagedObjectContext performBlockAndWait:] + 220
4 MyApp 0x100072fa8 specialized static NotificationSettingsMO.getSettings() -> NotificationSettingsMO (NotificationSettingsMO.swift)
5 MyApp 0x1000d6190 AppDelegate.getDataOnLaunch() ->() (AppDelegate.swift)
6 MyApp 0x1000da4bc specialized AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (AppDelegate.swift:99)
7 MyApp 0x1000d3eb8 @objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (AppDelegate.swift)
8 UIKit 0x1863f29c0 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 400
9 UIKit 0x186622184 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904
10 UIKit 0x1866265f0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684
11 UIKit 0x186623764 -[UIApplication workspaceDidEndTransaction:] + 168
12 FrontBoardServices 0x182bbf7ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
13 FrontBoardServices 0x182bbf618 -[FBSSerialQueue _performNext] + 168
14 FrontBoardServices 0x182bbf9c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
15 CoreFoundation 0x1811d509c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
16 CoreFoundation 0x1811d4b30 __CFRunLoopDoSources0 + 540
17 CoreFoundation 0x1811d2830 __CFRunLoopRun + 724
18 CoreFoundation 0x1810fcc50 CFRunLoopRunSpecific + 384
19 UIKit 0x1863eb94c -[UIApplication _run] + 460
20 UIKit 0x1863e6088 UIApplicationMain + 204
21 MyApp 0x10001ee18 main (Measurement+Network.swift:26)
22 libdispatch.dylib 0x180c9a8b8 (Missing)
你可以發佈崩潰日誌嗎?堆棧跟蹤一定會有助於確定究竟發生了什麼。 –
考慮如果您的獲取請求返回0結果會發生什麼。 – Jonah
「我已經在Crashlytics上發生了幾次崩潰」 您可以附上崩潰報告嗎? –