我正在开发和应用程序,它需要检查字符串是否已保存到数据库中。这似乎是一个简单的操作,但它需要半秒钟才能返回任何我认为很多的响应。我的问题是是否有任何方法可以减少该时间。感谢您的关注。
这是我当前的代码:
- (BOOL) isDeleted:(int)i {
NSString *value = [NSString stringWithFormat:@"deleted.*.%i", i];
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSString *entityName = @"Deleted";
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:entityName inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(deletedpics like %@)", value];
[request setPredicate:pred];
NSError *error;
NSArray *objects = [context executeFetchRequest:request error:&error];
BOOL returnBool = [objects count] >= 1 ? YES : NO;
return returnBool;
}