NSManagedObjectModel initWithContentsOfURL returns nil eventhough the modelURL is valid

后端 未结 6 495
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 13:42

my NSManagedObjectModel is returning nil eventhough the path is correct.

        NSString *modelKey = [NSString stringWithFormat:@\"/%@/Model\", name];
    N         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 14:11

    The by far safest way, if you have not yet versioned your model, is to do the following.

    1. Do not rename your xcdatamodeld file.
    2. Instead, create a brand new Data Model file with the new name.
    3. Keep the file empty and quit Xcode
    4. Open up a terminal and cd (change directory) into your old xcdatamodeld directory.
    5. Inside this directory should be a directory ending in xcdatamodel. Change into this directory.
    6. Inside the xcdatamodel directory you will find a file named contents. Copy this file into the same location under your newly named ?.xcdatamodeld/?.xcdatamodel directory.
    7. Open up Xcode and modify your Core Data code to access this new model.
    8. Build and test.
    9. Remove the old xcdatamodeld from your project.

    This works with basic models that have no versions.

提交回复
热议问题