I have an answer too, not saying Joshua is not correct. <-- He he...double negative.
I very recently had to do this and the correct approach really depends on how much data you wish to preload?
A) If it's a lot, then yes add a pre-populated store and load that at the start
B) If it's not, then just add the data through code manually
Both have Pro's and Con's. The biggest issue with A) is that when you go to update your model, then you will have to re-populate a new template. To me this can be an administrative nightmare.
So the next thing you might wonder is how to tell when to do either A) or B)? The answer is in the metadata of the persistent store. You really should only have one store, so let's assume this is the case. What I do is just get the metadata for "the store" and if my dict object does not return YES, then populate my table. If the save succeeds, then update the metadata of "the store" with a NSNumber BOOL value of YES.
I recommend using the class methods for NSPersistentStoreCoordinator. This way you are not required to perform another save on your context.
Code:
#pragma mark - Core Data Meta Data:
- (NSDictionary *) persistentStoreMetaData {
if ( ![_coreDataStore isExists] )
return [NSDictionary dictionary];
NSError * error = nil;
NSDictionary * dict = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType
URL:_coreDataStore
error:&error];
if ( error ) {
REPORT( errReportErrErrorStoreMetaDataGet );
return [NSDictionary dictionary];
}
return dict;
}
- (void) setPersistentStoreMetaData:(NSDictionary *)metaData {
if ( ![_coreDataStore isExists] ) return;
NSError * error = nil;
[NSPersistentStoreCoordinator setMetadata:metaData
forPersistentStoreOfType:NSSQLiteStoreType
URL:_coreDataStore
error:&error];
if ( error )
REPORT( errReportErrErrorStoreMetaDataSave );
}