I have a plist file which is an array of dictionaries. Where each dictionary contains a set of strings. Each dictionary represents a celebrity.
What I would like to do is populate Core Data with the contents of this plist on the applications first launch, after which I would like to somehow check core data for the existence of my data, and if there is data, load it from there, otherwise load the initial data from the plist file again.
I know its possible to populate core data from a plist, but is what I'm suggesting a viable solution? Or is there a better approach?
Jack
My sample code
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults objectForKey:@"dataImported"]) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"dict" ofType:@"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
for (NSString *key in [dict allKeys]) {
NSDictionary *node = [dict objectForKey:key];
MyClass *newObj = .....
}
[defaults setObject:@"OK" forKey:@"dataImported"];
[defaults synchronize];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With