我有事件,每个 Event 与 NSManagedObject Entertainment 有一对一的关系,而 Entertainment 有一对多的关系,并且有 NSSet 的事件
@interface Event : NSManagedObject
@property (nonatomic, retain) NSDate *creationDate;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSString * objectId;
@property (nonatomic, retain) NSString * price;
@property (nonatomic, retain) Entertainment *entertainment;
@property (nonatomic, retain) Place *place;
@property (nonatomic, retain) NSString *townName;
- (void)fillProperties:(NSDictionary *)JSON;
@end
@interface Entertainment : NSManagedObject
@property (nonatomic, retain) NSString * additionalInfo;
@property (nonatomic, retain) NSNumber * allCommentsLoaded;
@property (nonatomic, retain) id image;
@property (nonatomic, retain) NSString * imageURL;
@property (nonatomic, retain) NSString * info;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * objectId;
@property (nonatomic, retain) NSSet *comments;
@property (nonatomic, retain) NSSet *events;
- (void)fillProperties:(NSDictionary *)JSON;
@end
娱乐有很多子类所以我需要创建这样的 NSFetchedResultController 来获取具有特定类的娱乐的事件
我试过用
- (NSFetchedResultsController *)fetchedResultsControllerForEventsFromEntertainment:(Class)className
{
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([Event class])];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"entertainment isMemberOfClass: %@", [className class]];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"objectId" ascending:YES];
fetchRequest.sortDescriptors = @[sortDescriptor];
fetchRequest.fetchBatchSize = 20;
NSFetchedResultsController *fetchResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
return fetchResultsController;
}
但我得到错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Unknown/unsupported comparison predicate operator type'
***
我读到,当我们使用 SQLite 时,这种方法isMemberOfClass
不起作用,因为 SQLite 不知道这种方法。在通常的 NSPredicate 中,例如简单的数组,它必须工作。
那么如何从 SQLite 中获取具有特定类娱乐的事件呢?