LoginSignup
0
1

More than 3 years have passed since last update.

CoreData: warning: Multiple NSEntityDescriptions claim および CoreData: error: +[XXXX entity] Failed to find a unique match for an NSEntityDescription

Last updated at Posted at 2019-07-30

CoreDataで、デフォルトのオートマイグレーションを使うのではなく、自前で2つの NSPersistentContainerloadPersistentStores() して、一方から読み込み、もう一方に書き込むということをしました。

このとき書き込み側で、
CoreData: warning: Multiple NSEntityDescriptions claim ....
あるいは
CoreData: error: +[XXXX entity] Failed to find a unique match for an NSEntityDescription ...
のような警告もしくはエラーが発生しました。

やっていたこと。

let object = Xxxx(context: moc)
...attrbuteに値を代入...
do {
    try moc.save()
} catch {
    print("Failed to save new note")
}

これを下記のようにすることで回避できました。

let discription = NSEntityDescription.entity(forEntityName: "Xxxx", in: moc)!
let object = Xxxx(entity: discription, insertInto: moc)
moc.insert(object)
...attrbuteに値を代入...
do {
    try moc.save()
} catch {
    print("Failed to save new note")
}

mocNSPersistentContainerviewContext: NSManagedObjectContext です。

参考記事は以下です。
stackoverflow: Multiple NSEntityDescriptions Claim NSManagedObject Subclass

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1