Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

ios - Rename xcdatamodel file

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a hidden file called .xccurrentversion which should be in the same location as your whatever.xcdatamodeld file. Inside there is a reference to your model which needs to be updated with the new name.

In some cases, you'll have to remove the .xcdatamodeld file from the project and add it again to make it work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...