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

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

问题描述

需要做什么才能重命名.xcdatamodel文件。重命名.xcdatamodel文件名,并更改...

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

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

无法使用!我收到以下错误:

  2011-04-11 17:19:54.164 ProjectName [5826:207] ***终止应用程序由于未捕获异常'NSInvalidArgumentException',原因:'无法创建一个NIL模型的NSPersistentStoreCoordinator'
***第一次调用时调用堆栈:

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项目名0x000028ca - [ProjectNameAppDelegate makeSplitViewController] + 762
6项目名0x00002d44 - [ProjectNameAppDelegate应用中:didFinishLaunchingWithOptions:] + 68
7 UIKit的0x001f3c89 - [UIApplication的_callInitializationDelegatesForURL:有效载荷:暂停:] + 1163
8 UIKit的0x001f5d88 - [UIApplication的_runWithURL:有效载荷: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项目名0x00002599主+ 121
21项目名0x00002515启动+ 53

抛出的'NSException'
实例终止后,被称为

请注意:我使用Xcode4


解决方案

我一直有与Xcode 4相同的问题。不知道在Xcode 3中的行为。



首先,当你添加一个核心数据模型,你实际上得到一个.xcdatamodeld文件,这是一个像.xcodeproj文件的包。在finder中,您可以右键单击它和显示包内容。
你会看到它包含一个.xcdatamodel文件。



在我看来,你不能使用xcode重命名它。 Xcode将在UI中更改包文件(momd)的名称,但在文件系统上它没有实际更改。



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



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


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;

and

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'

Note: I'm using Xcode4.

解决方案

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

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.

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.

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)

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天全站免登陆