重命名 xcdatamodel 文件 [英] Rename xcdatamodel file

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

问题描述

需要做什么来重命名 .xcdatamodel 文件.重命名 .xcdatamodel 文件名,同时更改 ...

What do in need to do to rename the .xcdatamodel file. Renaming .xcdatamodel filename, along with changing ...

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"newfilename" withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
return __managedObjectModel;

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"newfilename.sqlite"];

不起作用!我收到以下错误:

doesn't work! I get following error:

2011-04-11 17:19:54.164 ProjectName[5826:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00fa15a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x010f5313 objc_exception_throw + 44
    2   CoreData                            0x00013853 -[NSPersistentStoreCoordinator initWithManagedObjectModel:] + 419
    3   ProjectName                         0x00003471 -[ProjectNameAppDelegate persistentStoreCoordinator] + 257
    4   ProjectName                         0x000031a4 -[ProjectNameAppDelegate managedObjectContext] + 100
    5   ProjectName                         0x000028ca -[ProjectNameAppDelegate makeSplitViewController] + 762
    6   ProjectName                         0x00002d44 -[ProjectNameAppDelegate application:didFinishLaunchingWithOptions:] + 68
    7   UIKit                               0x001f3c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
    8   UIKit                               0x001f5d88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
    9   UIKit                               0x00200617 -[UIApplication handleEvent:withNewEvent:] + 1533
    10  UIKit                               0x001f8abf -[UIApplication sendEvent:] + 71
    11  UIKit                               0x001fdf2e _UIApplicationHandleEvent + 7576
    12  GraphicsServices                    0x018f9992 PurpleEventCallback + 1550
    13  CoreFoundation                      0x00f82944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x00ee2cf7 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x00edff83 __CFRunLoopRun + 979
    16  CoreFoundation                      0x00edf840 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x00edf761 CFRunLoopRunInMode + 97
    18  UIKit                               0x001f57d2 -[UIApplication _run] + 623
    19  UIKit                               0x00201c93 UIApplicationMain + 1160
    20  ProjectName                         0x00002599 main + 121
    21  ProjectName                         0x00002515 start + 53
)
terminate called after throwing an instance of 'NSException'

注意:我使用的是 Xcode4.

Note: I'm using Xcode4.

推荐答案

我在 Xcode 4 中遇到了同样的问题.不知道 Xcode 3 中的行为是什么.

I have been having the same problem with Xcode 4. Don't know what the behaviour is in Xcode 3.

首先,当您在 xcode 中添加核心数据模型时,您实际上会得到一个 .xcdatamodeld 文件,它是一个类似于 .xcodeproj 文件的包.在finder中,您可以右键单击它并显示包内容".您会看到它包含一个 .xcdatamodel 文件.

Firstly, when you add a core data model in xcode, you actually get a .xcdatamodeld file which is a package like the .xcodeproj file. In finder, you can right click it and "Show Package Contents". You'll see it contains a .xcdatamodel file.

在我看来,您无法使用 xcode 完全重命名它.Xcode 将更改您在 UI 中看到的包文件(momd)的名称,但在文件系统上它实际上并未更改.

It seems to me you can't rename it fully using xcode. Xcode will change the name of the package file (the momd) as you see it in the UI, but on the file system it has not actually changed.

您得到的 nil 模型错误是因为它找不到新文件名 momd,因为它在磁盘上仍然具有旧名称.(我猜)

The nil model error you get is because it can't find the newfilename momd since it still has the old name on disk. (I guess)

我通过使用我想要的名称创建一个新模型来解决这个问题,然后在现有模型中,您可以单击并拖动并选择您的实体,然后将它们粘贴到新模型文件中.然后您可以删除旧的并将所有更改提交到您的 SCM.

I worked around this by creating a new model with the name I wanted, then in the existing model, you can click-drag and select your entities, then just paste them into the new model file. You can then delete the old one and commit all the changes to your SCM.

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

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