我正在尝试过滤对 CD 的提取请求,最初它可以工作,但现在它返回一个空数组。我检查了实体(提供者)并且我尝试过滤的键名是正确的(提供者名称)。我已经检查了 SQLite 数据库,并且名称与我正在搜索的 providerName 匹配的记录在那里。(见下面的附图)。有人可以查看我的代码,看看我是否做错了什么?谢谢:
- (NSArray* ) filterItemsFromCoreData : (NSArray* ) filters {
//create a managed object context
NSManagedObjectContext* context = [self managedObjectContext];
//create error container and fetch request
NSError* errMsg;
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
//get our filters from passed array
NSString* filterProviderName = [filters objectAtIndex:0];
NSString* filterProviderZip = [filters objectAtIndex:1];
NSString* filterProviderPhone = [filters objectAtIndex:2];
//create predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"providerName == %@", filterProviderName];
//create entity description
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Provider" inManagedObjectContext:context];
//add entity and predicate to fetch request
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];
//get the objects
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&errMsg];
NSLog(@"%@", fetchedObjects);
return fetchedObjects;
}
实体屏幕截图
SQLite 数据库