【发布时间】:2015-02-26 19:35:21
【问题描述】:
我正在使用这段代码来查找数据的存在。但是我收到了 Use of Undeclared Identifier "appDelegate" 这个错误。
- (IBAction)findContact:(id)sender {
CoreDataAppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context =
[appDelegate managedObjectContext];
NSEntityDescription *entityDesc =
[NSEntityDescription entityForName:@"Contacts"
inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSPredicate *pred =
[NSPredicate predicateWithFormat:@"(name = %@)",
_name.text];
[request setPredicate:pred];
NSManagedObject *matches = nil;
NSError *error;
NSArray *objects = [context executeFetchRequest:request
error:&error];
if ([objects count] == 0) {
_status.text = @"No matches";
} else {
matches = objects[0];
_address.text = [matches valueForKey:@"address"];
_phone.text = [matches valueForKey:@"phone"];
_status.text = [NSString stringWithFormat:
@"%lu matches found", (unsigned long)[objects count]];
}
}
我已包含 #import <CoreData/CoreData.h> 。我是否必须包含其他文件。当我保存数据时,它工作正常。
【问题讨论】:
-
导入CoreDataAppDelegate文件
-
在哪里可以找到 CoreDataAppDelegate 文件@Arunakumari
-
你的应用委托文件@rahul
-
哦......愚蠢的错误...... :( @Arunakumari
-
@Arunakumari 如何从实体中删除一些文本,就好像我想将搜索替换为删除一样\
标签: ios xcode core-data xcode6