以一对多关系从核心数据中获取所有对象

时间:2012-05-26 11:19:13

标签: objective-c database core-data

这是我的Exercise班级

@class Question;

@interface Exercise : NSManagedObject

@property (nonatomic, retain) NSNumber * aID;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSSet *listQuestion;
@end

@interface Exercise (CoreDataGeneratedAccessors)

- (void)addListQuestionObject:(Question *)value;
- (void)removeListQuestionObject:(Question *)value;
- (void)addListQuestion:(NSSet *)values;
- (void)removeListQuestion:(NSSet *)values;

@end 

这里是Question class

@class Exercise;

@interface Question : NSManagedObject

@property (nonatomic, retain) NSNumber * aID;
@property (nonatomic, retain) id jsAnswer;
@property (nonatomic, retain) Exercise *exercise;

@end

这些课程由coredata
创建 如何在每次练习中通过Question获取所有listQuestion个对象

1 个答案:

答案 0 :(得分:4)

这将为您提供给定练习的所有Question对象的数组:

NSArray *questions = [[exercise listQuestion] allObjects];