0
我需要将使用来自核心数据图表的提取请求检索到的值放入数组中,但不完全确定如何处理此问题。将核心数据值放入数组
我用下面执行读取:
NSString *entityName = @"Project"; // Put your entity name here
NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);
// 2 - Request that Entity
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
// 3 - Filter it if you want
request.predicate = [NSPredicate predicateWithFormat:@"belongsToProject = %@", _selectedProject];
// 4 - Sort it if you want
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"dateTaken"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
// 5 - Fetch it
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
[self performFetch];
正如你所看到的,我是过滤回来使用NSPredicate的值。
如何将这些值获取到数组中,并且还可以在实体处于数组中时为其选择单个属性,例如project.description或project.name?
感谢Eimantas我有一个数组的对象,但是我仍然需要做两件事情:通过阵列和输出数据
- 循环到一些HTML
- 单独选择从属性该数组,例如项目描述。
我使用以下for循环,要做的第一件:
for (int i=0; i < [projectListArray count]; i++)
{
NSString *tmp = (NSString *)[projectListArray objectAtIndex:i];
}
然而,这是返回错误:
-[Project length]: unrecognized selector sent to instance 0x1b9f20
2012-03-28 10:48:35.160 Project App[3973:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Project length]: unrecognized selector sent to instance 0x1b9f20'
看来好像我可能不会增加?
辉煌,谢谢你Eimantas。如果你不介意帮助,我有一件我想做的事情呢?我已经更新了我原来的问题。 – jcrowson 2012-03-28 09:51:36