【发布时间】:2013-02-17 16:40:45
【问题描述】:
我正在开发一个需要检查字符串是否已保存到数据库中的应用程序。这似乎是一个简单的操作,但它需要半秒钟才能返回任何我认为很多的响应。我的问题是是否有任何方法可以减少该时间。感谢您的关注。
这是我当前的代码:
- (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;
}
【问题讨论】:
-
您能解释一下实体和关系吗?我不太明白谓词。
-
不同实体之间没有关系。具体来说,这个实体只包含一个属性,即deletedpics。参考谓词,其想法是检查图片是否已被报告为已删除。我将删除的寄存器组织为“deleted.status(其他操作需要的变量).picturenumber”。在此功能中,我想在不考虑状态的情况下检查某张图片是否已被删除。这就是我使用这个谓词的原因。我希望现在更清楚了。
-
尝试索引该属性。
@"deleted.*.%i"是什么意思?
标签: ios objective-c core-data optimization nsfetchrequest