1
當我試圖從核心數據獲取超過1000個NSManagedObjects,我的應用程序崩潰與此消息:獲取超過1000時,核心數據碰撞對象
error: (1) I/O error for database at .../Documents/Stores/Model.sqlite.
SQLite error code:1, 'Expression tree is too large (maximum depth 1000)'
CoreData: error: (1) I/O error for database at .../Documents/Stores/Model.sqlite.
SQLite error code:1, 'Expression tree is too large (maximum depth 1000)'
我用它來獲取由用戶選擇的對象的代碼是這樣的:
NSManagedObjectContext *context = cdh.context;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Spot" inManagedObjectContext:context];
NSError *error = nil;
[request setEntity:entity];
request.includesPropertyValues = NO;
NSMutableArray *subPredicatesArray = [NSMutableArray array];
for (NSString *string in uuidStrings)
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@", @"sID", string];
[subPredicatesArray addObject:predicate];
}
NSCompoundPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:subPredicatesArray];
[request setPredicate:compoundPredicate];
NSArray *fetchedObjects = [context executeFetchRequest:request error:&error];
有沒有更好的方式來獲取1000+對象,這將不會導致我的應用程序崩潰?
我不知道該限制沒有。 :) –
直到我反對它,我也沒有! – EmilyP