Since I embeded fetch request in my model.xcdatamodeld, I need an instance of NSManagedObjectModel to get the fetch request from it. So I can do :
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
NSFetchRequest *fetchRequest = [managedObjectModel fetchRequestFromTemplateWithName:requestTemplateName
substitutionVariables:substitutionDictionary];
My question is about the managedObjectModel. Should I keep it in a property to reuse ? or should I call mergedModelFromBundles when needed ?
I don't know the cost of a call of '[NSManagedObjectModel mergedModelFromBundles:nil]' in terms of memory/rapidity. The the name "mergeModelFrom" make me think that this hide some operations that could lead to bad bad performance if executed for each request in my application. Is that correct ?
The Apple templates do this
This way the creation is only done if
managedObjectModel
==nil
, which is what you want.Notice this is written in the getter so you don't need to worry about remembering to instantiate
managedObjectModel
as this is taken care of and lazily instantiated when you actually try to access it.