How to get at a relationship items properties in Core Data?

前端 未结 3 1731
再見小時候
再見小時候 2021-01-27 05:48

Say you have a Core Data object called Workshop. It has a to-many relationship to a Student object.

How would I create an NSArray of the students within the Workshop?

3条回答
  •  逝去的感伤
    2021-01-27 06:49

    These relationships are normally declared as an NSSet in your NSManagedObject subclass, like this:

    @property (retain) NSSet* students;
    

    And there's also some special accessor methods:

    - (void)addStudentsObject:(NSManagedObject *)value;
    - (void)removeStudentsObject:(NSManagedObject *)value;
    - (void)addStudents:(NSSet *)value;
    - (void)removeStudents:(NSSet *)value;
    

    NSSets are similar to NSArrays, but they are not ordered, since Core Data does not guarantee a special sort order for managed objects.

提交回复
热议问题