Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problems creating static library with CoreData - Cannot create an NSPersistentStoreCoordinator with a nil model

How do I reference the Model that I have created in my static library project?

This returns null and throws and error because the resources live in this static library:

     //this code is in the static library
    - (NSManagedObjectModel *)managedObjectModel
{
    if (__managedObjectModel != nil) {
        return __managedObjectModel;
    }

    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"eCommerceEngine" withExtension:@"mom"];
    __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return __managedObjectModel;
}

How do I change this to pull from this static library?

like image 682
Slee Avatar asked Jun 04 '12 17:06

Slee


2 Answers

On the iPhone, static libraries have a .a extention and can only contain code. This means that any resources (xibs, images, etc…) must be packed either in a bundle or shipped separately than the library.

See iOS Library With Resources

like image 115
iTukker Avatar answered Nov 13 '22 17:11

iTukker


If you want to use a preconfigured model from a library, I would suggest building the model programmatically, using the Entity API, and not use a model file at all.

like image 25
Jody Hagins Avatar answered Nov 13 '22 18:11

Jody Hagins