アプリのコアデータと今日の拡張機能と違います。しかし、私の存在は常に空です。私はURLについていくつかの問題があると思う。PersistantStoreへのカスタムパスを設定する方法
私は自分のディレクトリをチェックします。そして、私は私の文書の状態が閉じていることを確認することができます。ファイルが存在します。しかし、私は本当に開くことはできません。それをどうやって開くのですか?
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
let coordinator = NSPersistentStoreCoordinator(managedObjectModel:
self.managedObjectModel)
let directory = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group....")
let url = directory!.appendingPathComponent("name.sqlite")
let document = UIManagedDocument(fileURL: url)
if document.documentState == .normal {
NSLog("document is normal status")
}
if document.documentState == .closed {
let fileExist = FileManager.default.fileExists(atPath: url.path)
NSLog("fileExist =\(fileExist)")
document.open(completionHandler: { (success: Bool) in
if success {
NSLog("document is opened!")
}else {
NSLog("document is still clodsed!")
return
}
})
NSLog("document is closed")
}
do {
try coordinator.addPersistentStore(ofType:
NSSQLiteStoreType,
configurationName: nil,
at: url,
options: nil)
} catch {
// Report any error we got.
NSLog("CoreData error \(error), \(error._userInfo)")
self.errorHandler(error)
}
return coordinator
}()
ここにログです:
ここではカスタムコアDATクラスのコアデータ方法がある
fileExist =true
document is closed
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIManagedDocument can only read documents that are file packages'
が正しいアクセスでは??
おかげでたくさん! –