1

我正在编写一个与服务器通信的应用程序。服务器使用 json,所以我在我的应用程序中使用这个 json,并将结果序列化为NSMutableDictionary然后用于创建新实体。

这是代码:

if (context == nil) {
    context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}

UserTable *ut = [NSEntityDescription insertNewObjectForEntityForName:@"UserTable" inManagedObjectContext:context];
ut.user = [Diz objectForKey:@"user"];
ut.email = [Diz objectForKey:@"email"];
ut.phone = [Diz objectForKey:@"phone"];

NSError *error = nil;    
if (![context save:&error]) {
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);        
}

所有在 iOS 4.3、iOS 6.0 和 6.1 中都能完美运行。在 iOS 5.0.1 中,此代码导致 exc_bad_Address 本地化[context save:&error]或有时本地化在ut.phone=[Diz objectForKey:@"phone"].

我只使用一个上下文(我用“isMainThread”函数测试线程组合),我能做什么?我的错误日志是空的,应用程序只是崩溃了。

编辑

感谢您的建议。我已经从设备中删除了我的应用程序,但我会尝试进行迁移。我启用了异常断点,但它是一样的......应用程序崩溃而没有记录任何错误(我也启用了 NsZombie)。在崩溃期间,在实体“UserTable”的属性上设置了绿色断点,如果我从保存中删除此属性,则在保存函数中设置断点。

编辑

经过多次测试,我检测到了这次崩溃的标准行为。我的实体 UserTable 有 31 个属性,如果我删除一个属性都可以正常工作...我已经尝试使用另一个名称和其他属性的名称重新创建实体,但行为是相同的...这是什么意思?实体的属性数量有限制吗?还有其他建议吗?

4

1 回答 1

0

Without further details it's difficult to understand what is going on.

Few suggestions in the meantime.

First. Provide some useful info about your Core Data model. Maybe, it's just a supposition, you've changed something in the model and now you need to remove the app already installed or perform a migration.

Second. Enable exceptions to see what happens Here you can follow this discussion "Run > Stop on Objective-C exception" in Xcode 4?.

Third. Use camelCase notation. Diz should be diz or a more explicit name like resultDictionary or whatever you want.

Fourth. Are you sure that a single context it is correct? When you have a lot of data to download from the server, the UI could freeze.

Finally, it could be better to a have a log of the error. What does it mean that this is empty?

于 2013-08-08T07:29:20.337 回答