简体   繁体   中英

Importing existing NSManagedObject (s) to new .xcdatamodeld

In my XCode 4.2.1 project, I created an .xcdatamodeld in my existing project and created new entities, relationship. I also created NSManagedObject classes using

Select .xcdatamodeld file 
Editor > Create NSManagedObject subclass

However when I ran the app it crashed at

- (NSManagedObjectModel *)managedObjectModel {

if (_managedObjectModel != nil) {
    return _managedObjectModel;
}
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"XXXXXXDataModel" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];  
return _managedObjectModel;

}

_managedObjectModel was not being created in

initWithContentsOfURL:modelURL

When I checked the package contents in the app folder it did not show the .mom and .omo files and there was only the Versions.plist file which was empty. I cannot recover the .xcdatamodeld file as it was not versioned and so I created a new data model file

I would like to know how can I import the existing entities to my new data model. I do not see any option in XCode 4.2.1 to do this. Any help?

Based on your question i feel that your trying to add core data after your project has been created. Since you had it earlier in your project but you couldn't recover it I guess this link will help in adding a core data module. http://wiresareobsolete.com/2009/12/adding-core-data-existing-iphone-projects/

Let me know if i understood your question wrong...

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