简体   繁体   中英

Changing the filename of a Core Data Managed Object Model

How do you change the filename of a Core Data managed object model?

I would like to change the filename for the Core Data managed object model in my Xcode project. I am not concerned about any migration issues.

I currently access the file in my code this way:

    NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"Template" ofType:@"momd"];

I have not found a way to change the momd filename/package that does not result in Xcode failing to find the changed filename.

You have a hidden file .xcurrentversion inside the "model".xcdatamodeld .

Just edit this file to match your model's new name:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs$
<plist version="1.0">
<dict>
        <key>_XCCurrentVersionName</key>
        <!-- This name should be the same as the file name !-->
        <string>"model".xcdatamodel</string> 
</dict>
</plist>

Done that several times.

Simply rename the xcdmodel and take care of the name when you load it from the bundle. Before you run, make sure to clean the target. (Eg remove all precompiled files, else he think he did compile the model already and thus your app fails to load the momd since they are there with the wrong name)

Pretty sure this is the cause: http://openradar.appspot.com/7500956

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM