Coredata: multiple xcdatamodeld files in one iOS project?

Is it possible to serve two xcdatamodeld master data in one project and load each according to the conditional?

I have BTPModel.xcdatamodeldandFTModel.xcdatamodeld

According to the comments, this line below does the following:

NSManagedObjectModel model = [NSManagedObjectModel mergedModelFromBundles:nil];

// view all models in the specified packages and merge them; if nil is specified as an argument, uses the main package

Can I do something like this? (pseudo code)

if (config == @"FT") {
   model = [NSManagedObjectModel load:@"FTModel.xcdatamodeld"];  
} else {
   model = [NSManagedObjectModel load:@"BPTModel.xcdatamodeld"];  
}

UPDATE:

I tried this

        NSURL *url = [[NSBundle mainBundle] URLForResource:@"F11iModel" withExtension:@"xcdatamodeld"];

No luck. url remains null.

UPDATE Extension - Mom. Now it works!

        NSURL *url = [[NSBundle mainBundle] URLForResource:@"F11iModel" withExtension:@"momd"];
+4
source share
1 answer

Of course you can. Just a few things to look out for:

load, initWithContentsOfURL. URL- URLForResource. .

, , ( ).

+1

Source: https://habr.com/ru/post/1608160/


All Articles