NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:0];
for (int i; i<[sectionInfo numberOfObjects]; i++) {
NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i];
[dict setObject:[[o valueForKey:@"frontCard"] description] forKey:@"frontCard"];
[dict setObject:[[o valueForKey:@"flipCard"] description] forKey:@"flipCard"];
}
在这一行
NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i];
我收到此警告:
warning: passing argument 1 of 'objectAtIndexPath:' makes pointer from integer without a cast
答案 0 :(得分:4)
objectAtIndexPath:
需要NSIndexPath
个对象。您传递的是一个不正确的整数。
您需要为给定的行和段索引创建索引路径,然后将其传入。我不知道您是如何获取托管对象的,但我只假设每个部分有一行。如果是这种情况,请执行此操作以获取其部分中的每个托管对象:
// It's also a good idea to initialize i in your loop and not just declare it
for (int i = 0; i<[sectionInfo numberOfObjects]; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:i];
NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:indexPath];
[dict setObject:[[o valueForKey:@"frontCard"] description] forKey:@"frontCard"];
[dict setObject:[[o valueForKey:@"flipCard"] description] forKey:@"flipCard"];
}