mar*_*son 24 cocoa core-data objective-c nspredicate ios
我目前有核心数据成功返回标题为特定实体的所有结果Event:
NSManagedObjectContext *context = [delegate managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Event"
inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSError *error;
NSArray *fetchResults = [context executeFetchRequest:request error:&error];
Run Code Online (Sandbox Code Playgroud)
Event实体的一个属性是标题为的字符串tid.我还有一个filterArray包含所有允许的tid值的数组.
如何才能使我的Core Data请求仅返回具有与其中一个值匹配的tid属性的事件filterArray?我相信答案与NSPredicate相关,但我还不熟悉它还没有达到我的意愿.
Nic*_*ver 61
试试这个:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"tid IN %@", filterArray];
[request setPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)
编辑
看看NSPredicate iPhone 3.2 SDK核心数据"IN子句"NSInvalidArgumentException异常.你有同样的错误.问题是列/属性名称中的拼写错误.语法应该没问题,它不能只找到tid.
| 归档时间: |
|
| 查看次数: |
18044 次 |
| 最近记录: |