Rename xcdatamodel file

前端 未结 10 2129
暖寄归人
暖寄归人 2020-12-05 00:55

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

NSURL *modelURL = [[NSBundle mainBundle] URLFo         


        
相关标签:
10条回答
  • 2020-12-05 01:17

    You can't change the name of any file in the application bundle after the app is built. Once the app bundle is fixed, it can't be changed at all.

    So, if you want to change the name of the model file on device, especially on user's devices, well, you can't.

    However, if you are still in development just change the name of the file in Xcode by clicking on the file's name and changing it.

    0 讨论(0)
  • 2020-12-05 01:19

    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.

    0 讨论(0)
  • 2020-12-05 01:20

    Thanks to all of you for helping me finally nail this one down. Here's how I fixed this after renaming my project in Xcode 4.2:

    1) Delete the reference to the *.xcdatamodeld file in your project. If it's like mine, an editor won't load when you select it. This tells me a link was broken in the rename.

    2) Right-click on the .xcdoeproj file for your project and select 'Show Package Contents'.

    3) Drag the *.xcdatamodeld file you find there back into your project. Done.

    My app buil

    0 讨论(0)
  • 2020-12-05 01:20

    XCode 10 Update & Swift 4

    Things may have changed a bit since XCode 4.2 It seems simplier in later versions because I just had to :

    1. Change OLD.xcdatamodeld to NEW.xcdatamodeld in fileInspector left tab

    2. In AppDelegate juste change the reference name : let container = NSPersistentContainer(name: "NEW")

    0 讨论(0)
  • 2020-12-05 01:32

    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.

    0 讨论(0)
  • 2020-12-05 01:36

    In XCode 4.3.2, it successfully renames the model file but I had to remove it from the project and add it again to make it work. Otherwise it was throwing

    0 讨论(0)
提交回复
热议问题