小编iMo*_*and的帖子

该操作无法完成.(可可错误133021.)+迅捷2

我目前正在我的应用程序中使用核心数据.我有以下实体:通知(to-1),People(to-many).实体如下:

通知实体的架构

People实体的架构

People实体具有唯一约束,即字段id.基本上我将从人员(将保存在People实体中)接收通知(将保存在通知实体中).如果具有特定ID的人发送多个通知而不创建新通知(这将是重复的),我想更新People实体.

当我做上述操作时,我收到以下错误:

该操作无法完成.(可可错误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 …
Run Code Online (Sandbox Code Playgroud)

cocoa core-data ios swift

4
推荐指数
1
解决办法
3445
查看次数

标签 统计

cocoa ×1

core-data ×1

ios ×1

swift ×1