Is there a way to get NSManagedObjectContext without having to call my AppDelegate every time?

I created the application from the Xcode template and selected Master Data as an option, so all master data delegates and basic methods will be included in the AppDelegate files.

Now, every time I have to get the context for using Core Data, I use the following code:

MovieCatalogAppDelegate *appDelegate = (MovieCatalogAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];

In any case, to get managedObjectContext without having to directly invoke MovieCatalogAppDelegate? I want to make it general, so my data files are not necessarily associated with MovieCatalogAppDelegate.h. Basically, I am trying to separate the code and make things more dynamic without knowing the direct names.

Thank.

+3
source share
2

.

  • Core Data , . , .

  • .

  • NSManagedObject, , NSManagedObjectContext managedObjectContext .

CIMGF.

+5

(Apple Documentation) , managedObjectContext , , , .

UIViewControllers ( ) ; :

self.managedObjectContext

, .

, , .

+4

Source: https://habr.com/ru/post/1790250/


All Articles