Search code examples
objective-cxcodecore-datansmanagedobject

How to set to NSManagedObject relationship to another NSManagedObject or stack of them in code in CoreData?


So, I have core data entities:ACCourse , ACStudent.ACCourse has relationship from one to many ACStudents(ACCourse <--->> ACStudent). I have to set to specific NSManagedObject(that is ACCourse) the relationship in code to other specific NSManagedObject(that is ACStudent).I didn't found any method to do such thing , as for example setting specific NSManagedObject attribute by KVC's setValue.What I need to do?


Solution

  • Xcode creates conveniences methods for to-many relations in the NSManagedObject subclass. To add a student to a course:

    [instanceOfACCourse addToNameOfRelationship: acStudentInstance];