过滤CoreData FetchRequest [英] Filtering a CoreData FetchRequest
问题描述
我正在尝试过滤fetchRequest。
I am having a brain meltdown trying to filter a fetchRequest.
我可以获得实体的每个记录的完整详细信息,但我只想
I'm able to get the full details of every record of the entity, but I only want the details on the record at the current indexPath.
这是我的代码目前所在的位置:
This is where my code is at present:
-(void) fetchStuff {
NSLog(@"%s", __FUNCTION__);
NSError *error = nil;
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *woodgie = [NSEntityDescription entityForName:@"WidgetEntity" inManagedObjectContext:context];
[fetchRequest setEntity:woodgie];
NSArray *fetchResults = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
fetchedObjects = [fetchResults objectAtIndex:selectedRow];
NSLog(@"selectedRow: %i", selectedRow); //0
NSLog(@"fetchedObjects: %@", fetchedObjects);
for (WidgetEntity *wigglies in fetchedObjects ) {
NSSet *peopleSet = [wigglies valueForKey:@"people"];
for (id person in peopleSet) {
personName = [person valueForKey:@"name"];
NSLog(@"name = %@", personName);
}
NSSet *keywordSet = [wigglies valueForKey:@"keyword"];
for (id keyWord in keywordSet) {
keywordName = [keyWord valueForKey:@"word"];
NSLog(@"Keyword = %@", keywordName);
.....
}
异常在此行for(WidgetEntity * wigglies in fetchedObjects){
(countByEnumeratingWithState:objects:count:]:无法识别的选择器发送到实例)..
I get an exception at this line " for (WidgetEntity *wigglies in fetchedObjects ) {" (countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance)..
但是事实是 - 我想要如何过滤数据。
but the truth is - I'm guessing how to filter the data.
任何帮助/指针都会感激。
Any help / pointers will be appreciated.
推荐答案
您正在谈论获取已选择的行中的记录 - 这表明您已< >获取记录并显示它们,大概在表视图中。
You are talking about fetching the record in the "row that has been selected" - this suggests that you have already fetched the records and are displaying them, presumably in a table view.
在这种情况下,不需要重新获取实体,只需使用数据源数组或获取结果控制器中相应索引的对象。
In that case there is no need to re-fetch the entities, simply use the object from the appropriate index in your data source array or your fetched results controller.
这篇关于过滤CoreData FetchRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!