【问题标题】:MagicalRecord crashes on first runtime on ios 8.1MagicalRecord 在 ios 8.1 的第一次运行时崩溃
【发布时间】:2015-03-10 17:01:09
【问题描述】:

我使用 MagicalRecord 在我的项目中添加了 CoreData,但它在此方法上崩溃:

+(NSString *) MR_entityName {
    NSString *entityName;

if ([self respondsToSelector:@selector(entityName)])
{
    entityName = [self performSelector:@selector(entityName)];
}

if ([entityName length] == 0)
{
    // Remove module prefix from Swift subclasses
    entityName = [NSStringFromClass(self) componentsSeparatedByString:@"."].lastObject;
}

return entityName;
}

在第一个 if 中,在控制台中我的 entityName 为 nil。 有人可以帮我吗? @Edit:我添加了一些代码,这就是我现在在控制台中拥有的:

TestCoreData[483:6632] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/macbookpro/Library/Developer/CoreSimulator/Devices/0E01E4C3-42E3-44A1-BE57-2A535715EE03/data/Containers/Data/Application/586065AE-FF44-4396-8999-9E06391595F6/Documents/ options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x7be94450 {NSUnderlyingException=unable to open database file, NSSQLiteErrorDomain=14} with userInfo dictionary {
NSSQLiteErrorDomain = 14;
NSUnderlyingException = "unable to open database file";

}

【问题讨论】:

  • 它给出什么类型的错误?
  • 在右侧控制台中,您可以编写 print 或其他内容,但没有显示任何内容,但我在断点中有一个 Thread1 EXC_BAD_ACCESS,我什么也做不了,只需按下停止运行按钮。
  • 访问不正确,我不知道为什么,如果从显示的方法开始,它会在第一时间发生。
  • 添加异常断点并尝试找出代码崩溃的地方

标签: ios objective-c core-data magicalrecord


【解决方案1】:

该错误发生得较早,而不是在此方法期间发生,但您在错误发生时忽略了该错误,因此您稍后会崩溃。

该错误具体描述了调用addPersistentStoreWithType:configuration:URL:options:error:时出现的问题,这是NSPersistentStoreCoordinator上的一个方法。不幸的是,Cocoa error 256 部分含糊不清,但NSSQLiteErrorDomain 指出了您的持久存储文件存在问题。

出现该问题是因为您传入的 URL 指向应用程序的文档目录。您需要将路径传递给文件名。该文件不必存在,如果需要,它将被创建。但它必须是文件的路径,因为 Core Data 不会为您组成文件名。

这意味着您正在传递类似[self applicationDocumentsDirectory] 作为 URL 的内容。它必须是该目录中的一个文件,例如[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MyPersistentStore.sqlite"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多