简体   繁体   English

iPhone的核心数据在获取请求时崩溃

[英]iPhone's Core Data crashes on fetch request

I'm using the following code to grab a few objects from SQLite store (which is a prepared SQLite db file, generated with Core Data on desktop): 我正在使用以下代码从SQLite存储(这是一个准备好的SQLite数据库文件,由桌面上的Core Data生成)中获取一些对象:

        NSFetchRequest * request = [[NSFetchRequest alloc] init];
        [request setEntity: wordEntityDescription];
        [request setPredicate: [NSPredicate predicateWithFormat: @"word = %@", searchText]];

        NSError * error = [[NSError alloc] init];
        NSArray * results = [[dao managedObjectContext] executeFetchRequest: request error: &error];

Eveyrthing seems to be setup properly, but executeFetchRequest:error: fails deeply inside Core Data (on NSSQLCore _newRowsForFetchPlan:selectedBy:withArgument) producing 256 error to the outside code. Eveyrthing似乎已正确设置,但是executeFetchRequest:error:在Core Data内部(在NSSQLCore _newRowsForFetchPlan:selectedBy:withArgument上)深深失败,导致外部代码产生256错误。

The only kink I had setting up managedObjectContext is I had to specify NSIgnorePersistentStoreVersioningOption option to addPersistentStoreWithType as it was constantly producing 134100 error (and yes, I'm sure my models are just identical: I re-used the model from the project that produced the SQL file). 我唯一设置好ManagedObjectContext的地方是我必须在addPersistentStoreWithType中指定NSIgnorePersistentStoreVersioningOption选项,因为它不断产生134100错误(是的,我确定我的模型是相同的:我重复使用了产生该项目的项目中的模型SQL文件)。

Any ideas? 有任何想法吗?

PS Don't mind code style, it's just a scratch pad. PS别介意代码样式,这只是一个便笺本。 And, of course, feel free to request any additional info. 并且,当然,可以随时要求任何其他信息。 It would be really great if someone could help. 如果有人可以帮助,那将是非常不错的。

Update 1 Alex Reynolds, thanks for willingness to help :) The code (hope that's what you wanted to see): 更新1 Alex Reynolds,感谢您的帮助:)代码(希望您看到的是这样):

NSEntityDescription * wordEntityDescription; //that's the declaration (Captain Obviousity :)
wordEntityDescription = [NSEntityDescription entityForName: @"Word" inManagedObjectContext: ctx];

As for predicate – never mind. 至于谓词-没关系。 I was removing the predicate at all (to just grab all records) and this didn't make any differences. 我完全删除了谓词(仅获取所有记录),但这没有任何区别。

Again, the same code works just fine in the desktop application, and that drives me crazy (of course, I would need to add some memory management stuff, but it at least should produce nearly the same behavior, shouldn't it?) 同样,相同的代码在桌面应用程序中也可以正常工作,这使我发疯(当然,我需要添加一些内存管理内容,但是至少它应该产生几乎相同的行为,不是吗?)

Can you add code to show how wordEntityDescription is defined? 您可以添加代码以显示wordEntityDescription的定义方式吗?

Also, I think you want: 另外,我认为您想要:

NSError *error = nil;

You may want to switch the equals symbol to like and use tick marks around the searchText field: 您可能需要将等号符号切换为like并在searchText字段周围使用刻度线:

[request setPredicate: [NSPredicate predicateWithFormat: @"word like '%@'", searchText]];

NSPredicate objects are not put together like SQL, unfortunately. NSPredicate是, NSPredicate对象没有像SQL那样放在一起。 Check out Apple's NSPredicate programming guide for more info. 查阅Apple的NSPredicate编程指南以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM