【发布时间】:2011-10-29 21:46:36
【问题描述】:
保存核心数据上下文时出现错误,这是日志:
Unresolved error Error Domain=NSCocoaErrorDomain Code=134030 "The operation couldn’t be completed. (Cocoa error 134030.)" UserInfo=0x1937a0 {NSAffectedStoresErrorKey=(
"<NSSQLCore: 0x156410>"
), NSUnderlyingError=0x181a60 "The operation couldn’t be completed. (Cocoa error 4.)", NSFilePath=/var/mobile/Applications/appid/Documents/appname.sqlite}, {
NSAffectedStoresErrorKey = (
"<NSSQLCore: 0x156410>"
);
NSFilePath = "/var/mobile/Applications/appid/Documents/appname.sqlite";
NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=4 \"The operation couldn\U2019t be completed. (Cocoa error 4.)\" UserInfo=0x181a30 {NSUnderlyingError=0x108ab0 \"The operation couldn\U2019t be completed. No such file or directory\"}";
}
我在移除和删除对象后收到此错误:
[productList removeMProductObject:product];
[[delegate managedObjectContext] deleteObject:product];
[delegate saveContext];
我还注意到我也收到以下场景的错误(调试):
1.
[productList removeMProductObject:product];
[delegate saveContext];
2.
[[delegate managedObjectContext] deleteObject:product];
[delegate saveContext];
3.
[[delegate managedObjectContext] deleteObject:product];
[productList removeMProductObject:product];
[delegate saveContext];
4.
[[delegate managedObjectContext] deleteObject:product];
[delegate saveContext];//error
[productList removeMProductObject:product];
[delegate saveContext];
5.
[productList removeMProductObject:product];
[delegate saveContext];//error
[[delegate managedObjectContext] deleteObject:product];
[delegate saveContext];
有时,我可能会将productList 或product 对象(均为NSManagedObject 类型)传递给其他控制器,始终在属性中使用assign 而从不使用retain。 productList 是一个可能包含许多 product 对象的对象。
我我能够创建新对象(NSManagedObject),但是在删除它们时,我得到了上面提到的错误。在模拟器中运行应用程序时,我会密切关注 sqlite 文件。在尝试删除对象(上面的代码)后,我注意到 .sqlite 文件已被删除。
我已经创建了一些没有问题的 Core Data iphone 应用程序,但我似乎在这里遇到了问题。我不相信我在做任何不寻常的事情,但也许我错过了一个小细节,但我不知道是什么!
为什么我的 .sqlite 文件被删除并导致保存时出现此错误消息?
如何找到更有用的错误消息,以便确定此错误的原因?
【问题讨论】:
标签: iphone cocoa-touch core-data