현재 응용 프로그램에서 핵심 데이터를 사용하고 있습니다. 나는 다음과 같은 엔티티를 가진다 : 알림 (to-1), People (to-many). 다음과 같이 실체는 다음과 같습니다작업을 완료 할 수 없습니다. (코코아 오류 133021) + swift 2
schema for Notification entity
인민 개체 필드 ID입니다 고유 제한 조건이 있습니다. 기본적으로 Person (People 엔터티에 저장 될 것입니다.)에서 알림 (Notification 엔터티에 저장 됨)을 받겠습니다. 특정 id를 가진 사람이 하나 이상의 알림을 보내고 새 항목을 만들지 않으면 (복제 될 사람) 엔티티를 업데이트하려고합니다. 내가 뭐하는 거지
의 I는 다음과 같은 오류 얻을 위 :
작업을 완료 할 수 없습니다 있습니다. (코코아 오류 133021)
누군가이 문제를 해결할 수 있도록 도와 줄 수 있습니까? 아래는 내 코드와 내가 저장하려고하는 데이터의 예입니다.
let entityNotification = NSEntityDescription.entityForName("Notification", inManagedObjectContext: self.managedContext)
let newNotification = Notification(entity: entityNotification!, insertIntoManagedObjectContext: self.managedContext)
newNotification.message = data["message"] as? String
if let actor = data["actor"] as? [String : AnyObject]
{
let newPeople = NSEntityDescription.insertNewObjectForEntityForName("People", inManagedObjectContext: self.managedContext) as! People
newPeople.id = actor["id"] as? Int
newPeople.name = actor["name"] as? String
newNotification.actor = newPeople
}
if let designator = data["designator"] as? [String : AnyObject]
{
let newPeople = NSEntityDescription.insertNewObjectForEntityForName("People", inManagedObjectContext: self.managedContext) as! People
newPeople.id = designator["id"] as? Int
newPeople.name = designator["name"] as? String
newNotification.designator = newPeople
}
do
{
try newNotification.managedObjectContext?.save()
}
catch let error as NSError
{
print(error.localizedDescription)
}
데이터 모델 :
let notif = ["message" : "testing",
"actor" : ["id": 1, "name": "jim"],
"designator" : ["id": 2, "name": "dave"]]
let notif1 = ["message" : "testing 1",
"actor" : ["id": 1, "name": "jim21"],
"designator" : ["id": 2, "name": "dave"]]
을
NSMergeByPropertyObjectTrumpMergePolicy
에 문맥에mergePolicy
을 설정 한 후 결과가 당신이 원하는 정말 무엇인지 확인하기 위해 그것을 밖으로 시도 할 필요가 기존 g'People' 인스턴스 – Paulw11CoreData를로드하려고 할 튜토리얼 : https://iosdevcenters.blogspot.com/2016/06/crud-operations-using-code-data-swift.html –