개발중인 iOS 응용 프로그램에서 핵심 데이터 모델을 효율적으로 작동시키는 데 많은 시간을 보내고 있습니다. 대부분의 경우 원활하게 작동하지만 모든 데이터를 단순한 우연으로로드하는 고유 한 오류가 발생했습니다. 테스트를 위해 iPhone을 실행하기 시작한 직후에 Core Data를 사용하여 데이터를로드하기 시작하면서 언니가 전화를 걸었습니다. 그 방해는 에 persistentStoreCoordinator
에서 abort()
함수를 호출 한 것처럼 보였기 때문에 다소 우연이었다. 여기 핵심 데이터 NSPersistentStoreCoordinator 전화 걸기, SWIFT
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
// Create the coordinator and store
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("DataModel.sqlite")
var failureReason = "There was an error creating or loading the application's saved data."
let mOptions = [NSMigratePersistentStoresAutomaticallyOption: true,
NSInferMappingModelAutomaticallyOption: true]
do {
try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: mOptions)
} catch {
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error as NSError
let wrappedError = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)")
abort() // THIS
}
return coordinator
}()
애플이 abort()
기능은 개발 과정에서 사용 될 필요가 생산 한 번 제거해야 댓글을 달았 어디 볼 수 있지만, 내가 ' 아무도이 유형의 오류를 올바르게 처리하는 방법을 보여줄 수 있는지 궁금합니다.
나는 방대한 양의 데이터를로드하지 않고 있으며이 인스턴스에서해야 할 일은로드 프로세스를 다시 시작하는 것뿐입니다.
오류가 잡히면 다시 시도 할 수있는 간단한 방법이 있습니까? 아니면 앱을 시작할 때 데이터 가져 오기를 수동으로 다시 실행해야합니까?
[Core Data Programming Guide] (https://developer.apple.com/library/ios/documentation/Cocoa/)의 샘플 코드에 따라'addPersistentStoreWithType' 호출을'dispatch_async'에 넣으십시오. Conceptual/CoreData /CoreDataStack.html # // apple_ref/doc/uid/TP40001075-CH4-SW1 초기화). 문제를 피할 수도 있습니다. – pbasdf
이것은 반복 가능합니까? 디버깅하는 동안 트리거 할 수 있습니까? 예외 메시지 광고 스택이란 무엇입니까? – Wain
@Wain - 귀하의 의견에 너무 오랫동안 답변을 드린 것에 대해 사과드립니다. 어쨌든이 문제는 완전히 무작위로 보입니다. 처음에는 xcode를 통해 휴대 전화에서 내 앱을 실행하는 중에 전화가 왔을 때 처음에 일어났습니다. 이제는 핀볼을 사용할 수있는 이유가 없어 다시 내게 일어났습니다. 오류는 기본적으로 "영구 저장소 마이그레이션 중 오류가 발생했습니다"라는 메시지를 표시 한 다음 "이유 = 대상 데이터베이스를 바꾸지 못했습니다"라는 오류 메시지가 표시됩니다. 이 데이터 모델을 조작 할 수 있습니까? 내 옵션은'NSMigratePersistentStoresAutomaticallyOption'과'NSInferMappingModelAutomaticallyOption'을 true로 설정했습니다. – Pierce