xcode 核心数据;可可错误 134100

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5517129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:42:47  来源:igfitidea点击:

Core Data; Cocoa error 134100

iphoneobjective-cxcodecore-dataios4

提问by max_

This is my first time with core data, and I am getting the following error.

这是我第一次使用核心数据,出现以下错误。

I would really appreciate it if you could tell me how to fix it.

如果您能告诉我如何修复它,我将不胜感激。

Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn't be completed. (Cocoa error 134100.)" UserInfo=0x5927880 {metadata=<CFBasicHash 0x59269a0 [0x1007400]>{type = immutable dict, count = 7,
entries =>
    2 : <CFString 0x5926e10 [0x1007400]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x5927240 [0x1007400]>{type = immutable, count = 0, values = ()}
    4 : <CFString 0x5927190 [0x1007400]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x5926ca0 [0x1007400]>{value = +320, type = kCFNumberSInt64Type}
    6 : <CFString 0x59271c0 [0x1007400]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x5927340 [0x1007400]>{type = immutable dict, count = 2,
entries =>
    0 : <CFString 0x5927280 [0x1007400]>{contents = "Details"} = <CFData 0x59272f0 [0x1007400]>{length = 32, capacity = 32, bytes = 0x434e180241ecf461e59580e640ff926b ... aa456d1410ed9d1b}
    2 : <CFString 0x5927260 [0x1007400]>{contents = "History"} = <CFData 0x59272a0 [0x1007400]>{length = 32, capacity = 32, bytes = 0x3437f77a5563363f66b9d72ea76e0ff1 ... be194eb9dd17cddc}
}

    7 : <CFString 0xe238b0 [0x1007400]>{contents = "NSStoreUUID"} = <CFString 0x5926fc0 [0x1007400]>{contents = "6C5FECCB-0B64-46EB-809B-E0A4577D1E90"}
    8 : <CFString 0xe23720 [0x1007400]>{contents = "NSStoreType"} = <CFString 0xe238f0 [0x1007400]>{contents = "SQLite"}
    9 : <CFString 0x59271f0 [0x1007400]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0x4d13e20 [0x1007400]>{value = +3, type = kCFNumberSInt32Type}
    10 : <CFString 0x5927220 [0x1007400]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x5927380 [0x1007400]>{contents = "2"}
}
, reason=The model used to open the store is incompatible with the one used to create the store}, {
    metadata =     {
        NSPersistenceFrameworkVersion = 320;
        NSStoreModelVersionHashes =         {
            Details = <434e1802 41ecf461 e59580e6 40ff926b 20004ce9 58eb965f aa456d14 10ed9d1b>;
            History = <3437f77a 5563363f 66b9d72e a76e0ff1 ed7f70fd cb7035e9 be194eb9 dd17cddc>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
        );
        NSStoreType = SQLite;
        NSStoreUUID = "6C5FECCB-0B64-46EB-809B-E0A4577D1E90";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "The model used to open the store is incompatible with the one used to create the store";
}
sharedlibrary apply-load-rules all
Current language:  auto; currently objective-c
kill
quit
Program ended with exit code: 0

My code is here: https://gist.github.com/898579

我的代码在这里:https: //gist.github.com/898579

回答by Eimantas

Here's the reason:

原因如下:

The model used to open the store is incompatible with the one used to create the store

用于开设商店的模型与用于创建商店的模型不兼容

And here's how you did it:

这是你是如何做到的:

  1. You created some entities with some attributes and wrote some code
  2. Launched the app, probably added some content
  3. Quit the app and added/changed some more entities with attributes
  4. You probably launched the app again and now it's giving you the error
  1. 您创建了一些具有某些属性的实体并编写了一些代码
  2. 启动了应用程序,可能添加了一些内容
  3. 退出应用程序并添加/更改更多具有属性的实体
  4. 您可能再次启动了该应用程序,现在它给了您错误

The reason for this is because your new managed object model is trying to use older version of storage (the one first time created when you launched the app).

这样做的原因是因为您的新托管对象模型试图使用旧版本的存储(启动应用程序时第一次创建的存储版本)。

The quick and dirty fix would be to remove the storage file (somewhere in ~/Library/Application Support/YOUR_APP/) and to launch your app again.

快速而肮脏的解决方法是删除存储文件(在 ~/Library/Application Support/YOUR_APP/ 中的某处)并再次启动您的应用程序。

For future reference - if you release an app and in next release the app has changed managed object model - you have to write migrations for it. All this and more is covered in core data programming cookbook in apple documentation.

为了将来参考 - 如果您发布了一个应用程序并且在下一个版本中该应用程序已更改托管对象模型 - 您必须为其编写迁移。Apple 文档中的核心数据编程手册中涵盖了所有这些以及更多内容。

回答by Wojtek

It should be enough if you remove the app from your simulator/device.

如果您从模拟器/设备中删除应用程序就足够了。

You don't have to change the files in your project (except choosing a current model and replacing the classes using menu: Editor/Create NSManaged Object Subclass).

您不必更改项目中的文件(除了选择当前模型并使用菜单替换类:Editor/Create NSManaged Object Subclass)。

回答by GameBegins

You should do following steps

您应该执行以下步骤

  1. Delete the application and Run it again, if it still shows the same error. Then it means that, you used the specific attributes/attribute with different type.
  2. Go to your .xcdatamodeled file and check the type of each attributes.
  3. Go to your code and check, while inserting the attributes/objects in core data, you used the same type of different. So, the point is type(NSString, NSDate...) of the attributes/objects in your code and .xcdatamodeled should be same. If not then it will give the error "Error Domain=NSCocoaErrorDomain Code=134100"
  1. 删除应用程序并再次运行它,如果它仍然显示相同的错误。那么这意味着,您使用了不同类型的特定属性/属性。
  2. 转到您的 .xcdatamodeled 文件并检查每个属性的类型。
  3. 转到您的代码并检查,在核心数据中插入属性/对象时,您使用了相同类型的不同。因此,重点是代码中属性/对象的 type(NSString, NSDate...) 和 .xcdatamodeled 应该相同。如果不是,那么它会给出错误“Error Domain=NSCocoaErrorDomain Code=134100”

回答by Soheil Novinfard

If you are in developing mode and don't want to delete the app each time you change the entities I recommend to use this solution:

如果您处于开发模式并且不想在每次更改实体时都删除应用程序,我建议您使用此解决方案:

- (void)removeCoreDataStorage {
    // Where does the SQLite file go?
    NSArray *documentDirectories =
    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                        NSUserDomainMask,
                                        YES);
    // Get one and only document directory from that list
    NSString *documentDirectory = [documentDirectories firstObject];
    NSString *path = [documentDirectory stringByAppendingPathComponent:@"model.sqlite"];

    NSError *error = nil;
    NSURL *storeURL = [NSURL fileURLWithPath:path];

    NSURL *storeURLWal = [NSURL URLWithString:[storeURL.absoluteString stringByReplacingOccurrencesOfString:@".sqlite" withString:@".sqlite-wal"]];
    NSURL *storeURLShm = [NSURL URLWithString:[storeURL.absoluteString stringByReplacingOccurrencesOfString:@".sqlite" withString:@".sqlite-shm"]];

    BOOL isRemoveItemAtURL = [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
    if (isRemoveItemAtURL == NO) {
        NSLog(@"NO RemoveItemAtURL. Reason: %@", error.localizedFailureReason);
    }

    BOOL isRemoveItemAtURLWal = [[NSFileManager defaultManager] removeItemAtURL:storeURLWal error:&error];
    if (isRemoveItemAtURLWal == NO) {
        NSLog(@"NO RemoveItemAtURL. Reason: %@", error.localizedFailureReason);
    }

    BOOL isRemoveItemAtURLShm = [[NSFileManager defaultManager] removeItemAtURL:storeURLShm error:&error];
    if (isRemoveItemAtURLShm == NO) {
        NSLog(@"NO RemoveItemAtURL. Reason: %@", error.localizedFailureReason);
    }
}

Don't forget to change the pathwith your own path.

不要忘记path用你自己的路径来改变。

回答by Nitin Vatsya

It happens with me as well and by removing STORE URL I fixed my this with bellow code - [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

它也发生在我身上,通过删除 STORE URL,我用下面的代码修复了这个问题 - [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

Clarification : delete the file at the storeURL and recreate it, if we don't want data to stick around between tests. Since the new tests have a new model version and the old file couldn't be opened properly. Also if we changed managed object model - we have to write migrations for it.

澄清:如果我们不希望数据在测试之间停留,请删除 storeURL 中的文件并重新创建它。由于新测试有一个新的模型版本,旧文件无法正常打开。此外,如果我们更改了托管对象模型 - 我们必须为它编写迁移。

回答by Vitek

Sometimes you need to load data from a store created by another application - e.g. one app is used just for loading data from external source and for saving into the store and the othe app uses this store full of data as a starting point.

有时您需要从另一个应用程序创建的存储中加载数据——例如,一个应用程序仅用于从外部源加载数据并保存到存储中,而另一个应用程序使用这个充满数据的存储作为起点。

I don`t want to say it is super-correct but in case you need it from time to time during the app development: just change the UUID in the store (by SQLVue etc.) to the right one which is expected by your app. You will find the UUID in the table called in most cases ZMETADATA in the only one column called Z_UUID. But remember - just for quick debugging / development purposes. Do not use this programmatically.

我不想说它是超级正确的,但如果您在应用程序开发过程中不时需要它:只需将商店中的 UUID(通过 SQLVue 等)更改为您的应用程序所期望的正确 UUID . 您会在大多数情况下称为 ZMETADATA 的表中找到 UUID,该表位于名为 Z_UUID 的唯一一列中。但请记住 - 仅用于快速调试/开发目的。不要以编程方式使用它。