So, I'm starting to learn Core Data for iOS and wrote this section of code:
- (void) viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; id delegate = [UIApplication sharedApplication].delegate; NSManagedObjectContext *objectContext = [delegate managedObjectContext]; NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Album"];
My question is what is the purpose of this line:
id delegate = [UIApplication sharedApplication].delegate;
I know that for a delegate, you need to pass the current instance of a specific object to the delegate property, which sets that object as a delegate to another object. My question is here when you do:
id delegate = [UIApplication sharedApplication].delegate;
what object is passed to this delegate property? The sharedApplication method returns one application instance that I accept, and then you get the delegate property for that single application instance. AppDelegate.h this delegate refer to the one used in the AppDelegate.h / AppDelegate.m ?
And if this delegation property is the same as that used in the AppDelegate.h / AppDelegate.m , there should not be a line of code in the AppDelegate.m file in the AppDelegate.m method, where we will go through the current instance of AppDelegate.m in the delegate property, similar to what we do for tableView :
self.tableView.delegate = self.
I do not see where this is done for the delegate property on this line:
id delegate = [UIApplication sharedApplication].delegate;
source share