Reputation: 841
Excuse the possible noob question. I'm building an app with Restkit 2.0 and having issues implementing the Core Data features. Following this tutorial I added the following code to my AppViewController (all other view controllers extend this class).
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.shadowImage = [UIImage new];
NSError *error = nil;
NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Jumplytics" ofType:@"momd"]];
// NOTE: Due to an iOS 5 bug, the managed object model returned is immutable.
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
// Initialize the Core Data stack
[managedObjectStore createPersistentStoreCoordinator];
NSPersistentStore __unused *persistentStore = [managedObjectStore addInMemoryPersistentStore:&error];
NSAssert(persistentStore, @"Failed to add persistent store: %@", error);
[managedObjectStore createManagedObjectContexts];
// Set the default store shared instance
[RKManagedObjectStore setDefaultStore:managedObjectStore];
// Override point for customization after application launch.
self.managedObjectContext = managedObjectStore.mainQueueManagedObjectContext;
}
I am getting the error:
property managedObjectContext not found on object of type 'AppViewController'
What can I do to fix this problem?
Upvotes: 0
Views: 352
Reputation: 119031
You probably don't want this code in viewDidLoad
in your superclass because that means it's being run for each subclass. So, each VC will have its own Core Data stack. It's more likely that you want a single Core Data stack that is used by all controllers (possibly in a singleton data controller).
Your error:
property managedObjectContext not found on object of type 'AppViewController'
seems unrelated to RestKit. It means that you are using self.managedObjectContext
when you don't have a property named managedObjectContext
. You just need to add the property so that it can be referenced.
Upvotes: 1