// // AppDelegate+Frank.m // FWToolkit // // Created by Matt Brooke-Smith on 18/07/2012. // Copyright (c) 2012 Future Workshops. All rights reserved. // #import "AppDelegate+Frank.h" #import #import #import @implementation AppDelegate (Frank) - (void) seedCoreData:(NSString *)json { NSArray *objectsArray = [json objectFromJSONString]; NSManagedObjectContext *managedObjectContext = [[RKObjectManager sharedManager].objectStore managedObjectContextForCurrentThread]; for (NSDictionary *objectDictionary in objectsArray) { NSString *entityName = [objectDictionary allKeys][0]; NSDictionary *dictionary = [objectDictionary objectForKey:entityName]; NSManagedObject *object = [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:managedObjectContext]; for (NSString *nextKey in [dictionary allKeys]) { if ([object respondsToSelector:NSSelectorFromString(nextKey)]) { NSObject *value = [dictionary objectForKey:nextKey]; if (value != [NSNull null]) { [object setValue:value forKey:nextKey]; } } } } NSError *error = nil; if (![managedObjectContext save:&error]) { NSLog(@"Error saving: %@", [error localizedDescription]); } } @end