gpt4 book ai didi

ios - Coredata 不支持谓词但仅支持非家庭计算

转载 作者:行者123 更新时间:2023-11-28 17:38:42 25 4
gpt4 key购买 nike

我正在按照苹果公司关于高效导入数据的示例 (http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/CoreData/Articles/cdImporting.html)

我的代码示例如下所示

NSString* predicateString = @" IN %@)";
predicateString = [NSString stringWithFormat:@"(%@%@", predicatePrefix, predicateString];

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity: [NSEntityDescription entityForName:entityName inManagedObjectContext: self.managedObjectContext]];
[fetchRequest setPredicate: [NSPredicate predicateWithFormat:predicateString, sortedServerIDs]];

// make sure the results are sorted as well
[fetchRequest setSortDescriptors: [NSArray arrayWithObject:
[[NSSortDescriptor alloc] initWithKey: predicatePrefix
ascending:YES]]];

NSError *error = nil;
NSArray *matchingManagedObjects = [__managedObjectContext executeFetchRequest:fetchRequest error:&error];

产生的错误是

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'unimplemented SQL generation for predicate : (businessesID IN {1, 2, 3, 4, 5, 6, 7, 39})'

然而,这在我家用电脑的模拟器上运行,并且在我的设备上运行!我在两台机器上都运行 xcode 4.2.1。

我试着按照这个答案: Does CoreData on iPhone support IN predicates?

但收到同样的错误

如果在我的机器上检查我的 SQLite 版本很重要,我有:

sqlite3 --version3.7.8 2011-09-19 14:49:19 3e0da808d2f5b4d12046e05980ca04578f581177

最佳答案

引用字段名时需要在格式字符串中使用 %K

NSString* predicateString = @" IN %@)";
predicateString = [NSString stringWithFormat:@"(%K%@", predicatePrefix, predicateString];

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity: [NSEntityDescription entityForName:entityName inManagedObjectContext: self.managedObjectContext]];
[fetchRequest setPredicate: [NSPredicate predicateWithFormat:predicateString, sortedServerIDs]];

// make sure the results are sorted as well
[fetchRequest setSortDescriptors: [NSArray arrayWithObject:
[[NSSortDescriptor alloc] initWithKey: predicatePrefix
ascending:YES]]];

NSError *error = nil;
NSArray *matchingManagedObjects = [__managedObjectContext executeFetchRequest:fetchRequest error:&error];

关于ios - Coredata 不支持谓词但仅支持非家庭计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9006804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com