NSManagedObjectModel versionIdentifiers [英] NSManagedObjectModel versionIdentifiers

查看:174
本文介绍了NSManagedObjectModel versionIdentifiers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSManagedObjectModel -versionIdentifiers的文档说,


Core Data框架不会给模型一个默认标识符,值。对于在Xcode中创建的模型,可以在模型检查器中设置此值。


我不确定,可能会帮助我,当我去编码模型迁移策略类。有谁知道如何在Xcode中设置这些标识符?

感谢。

解决方案

p>好吧,这种方法没有最终对我有帮助。我通过以下代码解决了我的Core Data迁移调试问题:

  NSURL * storeUrl = [NSURL fileURLWithPath:[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@Spark.sqlite]]; 

NSError * error = nil;
NSDictionary * sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType
URL:storeUrl
error:& error];

if(!sourceMetadata)
NSLog(@sourceMetadata is nil);
else
NSLog(@sourceMetadata is%@,sourceMetadata);

另一方面,我只是想出了我的原始问题fwiw的答案。 >

如果你去项目窗口并选择一个.xcdatamodel文件和'get info',大多数时候你会得到一个'File'Xxx.xcdatamodelInfo - General,Targets,Build和Comments选项卡。 (是的,大部分时间部分让我感到困惑。)



但是,如果您再次选择.xcdatamodel文件和'get info' (可能)得到一个非常不同的检查员 - 一个称为数据模型Xxx信息。此窗口有两个选项卡:外观和版本控制。版本控制选项卡允许您设置模型版本标识符。



底线:在Xcode中设置模型版本标识符类似于使用平台9 3/4 - 但是不像9 3/4一旦你到达那里,它不是很清楚为什么你想要在那里。


The documentation for NSManagedObjectModel -versionIdentifiers says,

The Core Data framework does not give models a default identifier, nor does it depend this value at runtime. For models created in Xcode, you set this value in the model inspector.

I am not sure, but I think that setting version identifiers might help me as I go about coding model migration policy classes. Does anyone know how one might set these identifiers in Xcode? I have poked around a fair bit without success.

Thanks.

解决方案

Okay, well this approach did not end up being helpful for me. I solved my Core Data migration debugging problems with the following code:

    NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Spark.sqlite"]];

    NSError *error = nil;
    NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType
                                                                    URL:storeUrl
                                                                    error:&error];

    if (!sourceMetadata)
        NSLog(@"sourceMetadata is nil");
    else
        NSLog(@"sourceMetadata is %@", sourceMetadata);

On the other, I just now figured out the answer to my original questions, fwiw.

If you go to your project window and select a .xcdatamodel file and 'get info', then most of the time you will get a 'File "Xxx.xcdatamodel" Info' window - with 'General', 'Targets', 'Build' and 'Comments' tabs. (Yes, the "most of the time" part has me confused.)

However, if you then select your .xcdatamodel file again and 'get info', you will (probably) get a very different inspector - one called 'Data Model "Xxx" Info'. This window has two tabs: 'Appearance' and 'Versioning'. The Versioning tab lets you set the Model Version Identifier.

Bottom line: Setting the Model Version Identifier in Xcode is akin to making your way to Platform 9 3/4 - but unlike 9 3/4 once you get there, it's not really clear why you'd want to be there.

这篇关于NSManagedObjectModel versionIdentifiers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆