我正在使用CoreData来存储一些实体。我在CoreData中有一些实体,想要使用NSPredicate
来获取它们。我使用以下代码但返回的objectsArray
为空。谁能告诉我我做错了什么?
AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = delegate.managedObjectContext;
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Devices"];
NSError *error;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"deviceName == %@", deviceNameString];
[request setPredicate:predicate];
[request setEntity:[NSEntityDescription entityForName:@"Devices" inManagedObjectContext: context]];
NSArray *objectsArray = [context executeFetchRequest:request error:&error];