I need to insert few NSManagedObject subclass instances (Object B) in the to-many relationship of the Object A, but I don’t know if these Objects B is already exist in Object A relationship. What would happen if I will insert them? Would they be inserted twice, or Core Data wouldn’t do that?
Share
Because the to-many relationship is accessed as a
NSSet, only unique objects will be added (this is a feature of NSSet’s) so you don’t need to worry about checking to see if it is already there first.To quote the documentation for
NSSet:and from the
NSMutableSetdocumentation: