Recently I started learning CoreData.
Figured out how to create a database, create a table (Event) and add the data.
Clear with this. Now the problem.
In my project, there are several classes.
All database activities (creating / filling), I am doing in the first class (myProject.h / myProject.m)
Now I want to get the data on request in a different class (myProjectOtherClass.m)
How can I do this?
I understand how to do it in class myProject.m, but how to do it in myProjectOtherClass.m?
Recently I started learning CoreData. Figured out how to create a database, create a
Share
I assume that you have imports for your entities (TableNames) in myProject.h / myProject.m to see the attributes of these data entries.You should import the required data entity also in other classes where you want to use them, insert delete etc.
You need to create new instances of
NSManagedObjectContextfor fetching results or inserting new entities and for that purpose you need a property on persistence store variable(NSPersistentStoreCoordinator).It shows you where your store is located.In simpliest case if you have created the project using CoreData template of Xcode, they all reside in AppDelegate so you can make it visible outside of AppDelegate with a property.UPDATE :
Or alternatively you can also put a property on a single MOC in AppDelegate and use it for every single Core Data operation