这里我得到了fetchedObjects中的值。如何更新数组中的值?
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Reserve" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
//NSSortDescriptor tells defines how to sort the fetched results
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"number" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSLog(@"sort count%d",[sortDescriptors count]);
fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(number = 100)", self.txtReserve.text];
// [fetchRequest setPredicate:predicate];
[fetchedResultsController.fetchRequest setPredicate:predicate];
self.fetchedObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"Count of array::::%d",[fetchedObjects count]);
NSManagedObject *device = [fetchedObjects objectAtIndex:0];
NSLog(@"device::::%@",device);
答案 0 :(得分:0)
我建议您阅读/观看Core Data上的一些书籍/教程。您缺少对该技术的基本了解。
首先,您收到的对象代表数据库中的对象,您必须知道实体描述才能获取数据。例如,获取“Reserve”实体的“number”属性的最基本方法是......
[managedObject valueForKey:@"number"];
如果您使用Xcode(或称为mogenerator的工具),您可以为您的实体生成子类,并且可以通过自定义访问器方法更轻松地访问数据。