以一对多关系从 coredata 中获取所有对象
Posted
技术标签:
【中文标题】以一对多关系从 coredata 中获取所有对象【英文标题】:fetch all object from coredata in one-to-many relationship 【发布时间】:2012-05-26 11:19:13 【问题描述】:这是我的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 Exercise;
@interface Question : NSManagedObject
@property (nonatomic, retain) NSNumber * aID;
@property (nonatomic, retain) id jsAnswer;
@property (nonatomic, retain) Exercise *exercise;
@end
这些类是由 coredata 创建的
如何在每个练习中通过listQuestion
获取所有Question
对象
【问题讨论】:
【参考方案1】:这将为您提供给定练习的所有 Question 对象的数组:
NSArray *questions = [[exercise listQuestion] allObjects];
【讨论】:
以上是关于以一对多关系从 coredata 中获取所有对象的主要内容,如果未能解决你的问题,请参考以下文章
NSPredicate:“添加”一对多关系CoreData中所有实体的属性值