我的 iOS 应用程序上有 coredata,但我正在做的是从表中收集所有值,在我的例子中是一个 Questions 表,其中包含以下内容:
@property (nonatomic, retain) NSString * answerA;
@property (nonatomic, retain) NSString * answerB;
@property (nonatomic, retain) NSString * answerC;
@property (nonatomic, retain) NSString * answerD;
@property (nonatomic, retain) NSString * correctAnswer;
@property (nonatomic, retain) NSString * question;
@property (nonatomic, retain) NSString * timeStampLastUsed;
@property (nonatomic, retain) NSNumber * gameType;
@property (nonatomic, retain) NSString * continent;
我以这种方式获得所有值:
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Questions" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
我想要的是在 NSArray *fetchedObjects 中只有具有特定游戏类型的问题。
我怎样才能用 NSPredicate 做到这一点?
谢谢最好的问候