title: The operation couldn’t be completed. (Cocoa error 133021.) + swift 2
body: <p>I am currently using core data in my application. I have the following entities : Notification (to-1), People (to-many). The entities are as follows:</p>
  
  <p><a href="http://i.stack.imgur.com/YU0b0.png" rel="noreferrer">schema for Notification entity</a></p>
  
  <p><a href="http://i.stack.imgur.com/ZZGjg.png" rel="noreferrer">schema for People entity</a></p>
  
  <p>The People entity has a unique constraint which is the field id. Basically I'm going to receive notifications(which will be saved in Notification entity) from persons (which will be saved in People entity). I want to update the People entity if a person with a specific id sends more than one notifications and not create a new one (which will be duplicate).</p>
  
  <p>When I am doing the above I get the following error:</p>
  
  <p>The operation couldn’t be completed. (Cocoa error 133021.)</p>
  
  <p>Can someone please help me solve this issue. Below is my code and an example of the data that I am trying to save.</p>
  
  <pre><code>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)
      }
  </code></pre>
  
  <p>Data model:</p>
  
  <pre><code>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"]]
  </code></pre>