2017-06-20 10 views
0

永続的なコンテナを使用してtableviewcontrollerにデータをロードしていますが、データを保存するたびにこのような奇妙なエラーが表示されます。iOSコアデータNSCocoaErrorDomain 134020

他のVC(タブバーから)を読み込んだ後、フレンドリストページにアクセスするたびにエラーが発生します。 友達リストページを直接開いてもエラーは発生しません。

注*:コアデータにアクセスできるすべてのViewControllerにコンテナの初期化があります。

私を助けることができますか?

An error occurred while saving: Error Domain=NSCocoaErrorDomain Code=134020 "(null)" UserInfo={NSAffectedObjectsErrorKey=<Friend: 0x6080008954a0> (entity: Friend; id: 0x608000a33340 <x-coredata:///Friend/t78E3F129-DFFC-46DC-B542-7B2378382AB587> ; data: { 
    accepted = 1; 
    canAccept = 0; 
    name = "Foo Bar"; 
    profilePicture = nil; 
    username = foobar; 
}), 
NSUnderlyingException=Store <NSSQLCore: 0x600000375840> (URL: file:///Users/foobar/Library/Developer/CoreSimulator/Devices/69C6FA49-8B83-4289-AA3B-90D8FE065492/data/Containers/Data/Application/27388AC0-B1C6-4D25-8194-3DCA8AF4818C/Library/Application%20Support/Renungan.sqlite) cannot hold instances of entity (<NSEntityDescription: 0x60800035c510>) name Friend, managedObjectClassName Friend, renamingIdentifier Friend, isAbstract 0, superentity name (null), properties { 
accepted = "(<NSAttributeDescription: 0x6080006e9080>), name accepted, isOptional 0, isTransient 0, entity Friend, renamingIdentifier accepted, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)"; 
canAccept = "(<NSAttributeDescription: 0x6080006e9100>), name canAccept, isOptional 0, isTransient 0, entity Friend, renamingIdentifier canAccept, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)"; 
name = "(<NSAttributeDescription: 0x6080006e9180>), name name, isOptional 0, isTransient 0, entity Friend, renamingIdentifier name, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)"; 
profilePicture = "(<NSAttributeDescription: 0x6080006e9200>), name profilePicture, isOptional 1, isTransient 0, entity Friend, renamingIdentifier profilePicture, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)"; 
username = "(<NSAttributeDescription: 0x6080006e9280>), name username, isOptional 0, isTransient 0, entity Friend, renamingIdentifier username, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)"; 
}, subentities { 
}, userInfo { 
}, versionHashModifier (null), uniquenessConstraints (
)} 

は、ここでは、すでに問題の原因を疑うように見えます私のコンテナの初期化

container.loadPersistentStores { (_, error) in 
      if let error = error { 
       print("Unable to Load Persistent Store") 
       print("\(error), \(error.localizedDescription)") 

      } else { 
       self.setupView() 

       do { 
        let acceptedPredicate = NSPredicate(format: "accepted = %@", NSNumber(booleanLiteral: true)) 
        self.fetchedResultsController.fetchRequest.predicate = acceptedPredicate 
        try self.fetchedResultsController.performFetch() 
       } catch { 
        let fetchError = error as NSError 
        print("Unable to Perform Fetch Request") 
        print("\(fetchError), \(fetchError.localizedDescription)") 
       } 

       self.updateView() 
      } 
     } 

答えて

0

です。同じファイルを指し示す複数の永続コンテナを作成して動作させることはできません。すべての異なるコンテナはすべて同時にファイルに書き込もうとしており、お互いを混乱させます。アプリケーション全体に対して単一の永続コンテナを作成し、そのコンテナのみを使用します。破損したファイルを削除するには、再度実行する前にアプリを削除してください。

+0

ここで、単一の永続コンテナ@jon-roseを作成する必要がありますか? 私は今、コアデータにアクセスする機能を持つすべての単一のviewcontrollerにコンテナを作成しました。 私が作るすべてのコントローラで、私はそれを上の '' 'に宣言します。private let container = NSPersistentContainer(name:" Renungan ")' '' –

+0

appDelegateまたはsharedSingleton。 –

+1

このような '' 'プライベートletコンテナ=(UIApplication.shared.delegateとして!AppDelegate).persistentContainer''' ?? –

関連する問題