Application Delegation Best Practices

I make several applications here and there, and I know my way. I was always confused by access to global attributes and where it is best to set them. I have a few questions about access to things and how to access them.

Do I need to include the application delegate header file in any other file that you want to access? Say I have a view controller that I would like to use, do I need to enable .h inside my view controller .h? Or I can install:

@class AppDelegate;

You can only access the delegate by typing:

[UIApplication sharedApplication].delegate

EVERYONE and every time? Is that what I'm just used to? Or I can set the following in my implementation in each .h:

AppDelegate *delegate;

And inside the function, initput a singleton instance in this variable?

, , , , .

+2
2

, , ? , , , .

, . init, , .

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

, MyAppDelegate .

+5

, #define , - :

MYAPPDELEGATE.customProperty = blah;

, , , #defines , , .

, , , .

0

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


All Articles