I created a non core data project. I now want to use core data. In the build phases, I linked my binary with CoreData.framework. In my application delegate method, I want to manually create a managed object context like so
NSManagedObjectContext *aContext = [[NSManagedObjectContext alloc] init];
When I do the above, I get the following error,
Receiver 'NSManagedObjectContext' for class message is a forward declaration.
Any suggestions on what I might be doing wrong?
A managed object context represents a single object space, or scratch pad, in a Core Data application. A managed object context is an instance of NSManagedObjectContext . Its primary responsibility is to manage a collection of managed objects.
Most apps need just a single managed object context. The default configuration in most Core Data apps is a single managed object context associated with the main queue. Multiple managed object contexts make your apps harder to debug; it's not something you'd use in every app, in every situation.
An object space to manipulate and track changes to managed objects.
Creating NSManagedObject Subclasses To create a subclass of NSManagedObject , in the Xcode Core Data model editor, select the entity, and in the Entity pane of the Data Model inspector, enter the name in the Class field. Then create the subclass in Xcode.
You need to import CoreData/CoreData.h in your application delegate's header file:
#import <CoreData/CoreData.h>
Since you probably use it through outyour application you should put it in the precompiled header file, YourApp-Prefix.pch:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#endif
Just write #import < CoreData/CoreData.h > in your implementation file. It will work
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