I am currently working though this tutorial, that explains how to add Core Data to an existing project.
I am up to the part titled
AppDelegate.m
It says this:
Implement applicationDocumentsDirectory, and explicitly write accessor methods for each new property as opposed to simply using the
@synthesize keyword. Note in the persistentStoreCoordinator accessor
there is a location where you must name the SQLite file used for the
store; this should most likely be your project name. Remember to
properly release each object in dealloc:
I do not understand what this part is asking me to do
Implement applicationDocumentsDirectory, and explicitly write accessor methods for each new property as opposed to simply using the
@synthesize keyword.
From what I can tell its asking me to implement the variables differently from how I normally do them with the @synthesize.. but im not sure how else to do it…if someone could help me out that would be awesome.
Here is my property code
//Core Data
@property (nonatomic, strong, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, strong, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
I think what that particular paragraph is saying is that you need to create custom getters for your CoreData ivars.
For instance, if you look at a fresh new template project created by Xcode, you will notice that all of the CoreData properties have their custom getters set, and they lazily instantiate/create the ivars the first time you access them.
For instance, the method below checks if your managedObjectContext ivar is not nil, in which case the context has already been created so the getter method will simply return it to the calling method (which is typically you accessing the
managedObjectContextproperty withself.managedObjectProperty)The applicationsDocumentDirectory method is just a convenience method that returns the path to the documents directory which will then be used by your persistent store coordinator to set the path for your CoreData database file.
Your best bet is to create a new project and copy the entire CoreData stack from the AppDelegate onto your existing project. You will then need to create a managed object model and make sure you have set the name correctly in the NSManagedObjectModel method, then you should be good to go.