I'm working on a static library using Core Data framework. Sadly, I'm unable to access my Bundle / .momd file generated.
What I've done :
- Create my Data Model (Model.xcdatamodeld file)
- Create a new Bundle target (named sdkResources) where I've added my xcdatamodeld file in Compile Sources and linked CoreData.framework
- Inside my sdk target, I've put sdkResources.bundle inside "Copy Bundle Resources" section
- Edit my sdk scheme and added sdkResources target in the build section
My not working code :
NSString *staticLibraryBundlePath = [[NSBundle mainBundle] pathForResource:@"sdkResources" ofType:@"bundle"];
NSURL *staticLibraryMOMURL = [[NSBundle bundleWithPath:staticLibraryBundlePath] URLForResource:@"Model" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:staticLibraryMOMURL];
Returns :
[FAILED], NSInvalidArgumentException "Cannot create an NSPersistentStoreCoordinator with a nil model" raised
The problem seems to be the "mainBundle" access because the code below is working when I run my sdk tests (at least no error)
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSURL *staticLibraryMOMURL = [bundle URLForResource:@"Model" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:staticLibraryMOMURL];
But when I want to use my sdk inside an other App (using a podFile file) I can't access my bundle and get the same error :/
I've read and try a lot but nothing seems to work. I don't have a lot of experience in iOS dev and I'm trying my best to understand what's going on but it's a dead end to me now :(
Regards
- Edit / Screens of my project configuration
I don't know why sdkResources.bundle is red.. Hope this is what you're asking for, thanks.
Edit : After fixing path to sdkResources.bundle
Edit :
Ok, I'm really close to the solution, my bundle is successfully copied inside my final App but I can't access my Model and it's only working inside my sdk tests when I'm using [NSBundle bundleForClass:[self class]] instead of [NSBundle mainBundle]. It's probably just a stupid configuration but.. yeah.. I'll keep digging !