title: swift coredata - unrecognized selector sent to instance
body: <p>When setting an attribute (NSSet) of an NSManagedObject for coredata, it will display this error at runtime:</p>
  
  <pre><code>-[__NSArray0 isEqualToSet:]: unrecognized selector sent to instance 0x1551ad60
  </code></pre>
  
  <p>First, I have no idea which instance is identified as 0x1551ad60.</p>
  
  <p>Second, I understand the instance doesn't understand 'isEqualToSet', however I am not calling it anywhere in my code which must mean it is called by the framework somewhere? I'm guessing my code is incorrect but I don't understand how or where.</p>
  
  <p>I am running Xcode 7.3 with Swift (2.0 I think?) and I have removed/reinstalled the app many times on the iPad.</p>
  
  <p>Here is my code, the problem line is marked. Please help, this is driving me mad!</p>
  
  <pre><code>    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
      let managedContext:NSManagedObjectContext = appDelegate.managedObjectContext
  
      let carEntity = NSEntityDescription.entityForName("Car", inManagedObjectContext:managedContext)
      let carObj = NSManagedObject(entity: carEntity!, insertIntoManagedObjectContext: managedContext)
      carObj.setValue("Toyota", forKey: "name")
      carObj.setValue("Blue", forKey: "colour")
  
      let wheelEntity = NSEntityDescription.entityForName("Wheel", inManagedObjectContext:managedContext)
      let wheelObj = NSManagedObject(entity: wheelEntity!, insertIntoManagedObjectContext: managedContext)
      wheelObj.setValue(Float(1.3), forKey: "tread")
  
  (Original code)
  var wheelObjArray = [NSManagedObject]()
  wheelObjArray.append(wheelObj)
  let wheelSet = NSSet(array: wheelObjArray)
  carObj.setValue(wheelSet, forKey: "wheels")
  ^^ error here: unrecognized selector sent to instance
  (/Original code)
  
  (Edited code)
  var wheelObjArray = carObj.mutableSetValueForKey("wheels")
  wheelObjArray.addObject(wheelObj)
  ^^ error here: *** -[NSSet intersectsSet:]: set argument is not an NSSet
  (/Edited code)
  
  do {
      try managedContext.save()
      print("Success!")
  } catch let error as NSError  {
      print("Failed to save: \(error), \(error.userInfo)")
  }
  </code></pre>
  
  <p>My CoreData model is as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/i8kIm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i8kIm.png" alt="Car"></a></p>
  
  <p><a href="https://i.stack.imgur.com/KGeEs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KGeEs.png" alt="Wheel"></a></p>
  
  <p>Edit: Car relationship "wheels" is now a one-to-many relationship.</p>
  
  <p>Edit #2: Code updated.</p>
  
  <p>Edit #3: One possible workaround for this problem is to remove the inverse relationship from Wheel "car".</p>