Core Data model files does not load on rename

前端 未结 6 949
眼角桃花
眼角桃花 2020-12-29 09:52

I have a model file thats named \"Model\". If I rename it to \"SomeOtherName\" it just does not get loaded.

initWithContentsOfURL returns nil and:

6条回答
  •  生来不讨喜
    2020-12-29 10:16

    The most likely cause is that new name is not being included in the build target. Check the target for included files and make sure the new name is there. If not, add it. If the old file name is there remove it before adding the new one.

    If it is in the build target, confirm that the new file retains the .xcdatamodel extension. Check the built product bundle to confirm that it includes a .mom or .momd file with the new name.

    Your mergedModelFromBundles: should look like:

    NSManagedObjectModel *mom=[NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:[NSBundle mainBundle]];
    

    ... or:

    NSManagedObjectModel *mom=[NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObjects:[NSBundle mainBundle],nil] ]; 
    

提交回复
热议问题