I’m just learning core data and mostly coping, but having a little bit of trouble thinking about how I’ll implement it.
I want to access the same Core Data from throughout my app. What would be the best way to access it from multiple classes? Would it be recommended to have it as a global variable (normally not recommended in object oriented programming), or to pass it as an instance variable between classes?
Core data model will be available throughout your app. You can easily access the managed object through out your app. You just need to make an instance of the
AppDelegateclass.Say for example you have stored contacts. You can just use
[managedObject valueForKey:@"name"]in any of the view controllers.1. Create an instance of the appDelegate
2. Get the context,fetch request and entity description.
3. Get the managed object from the array.
4. Pass the name object using a
singleton(or any convenient method) pattern, in other view controllers that you need it.