Home > DeveloperSection > Forums > In Objective-C proper use of Application delegate
Nigel Bunyan
Nigel Bunyan

Total Post:20

Posted on    December-13-2015 11:35 PM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 432  View(s)
Rate this:

I want to call a web-service to get the users information, and after I want to be able to access this information from anywhere in our application using like this:

MyDelegate *delegate = [[UIApplication sharedApplication] delegate];
user = delegate.u;

Is setting an instance variable as a User object in the app delegate and referencing it from there when needed a poor way of going about it? I typically set it there upon the user's login.

Tarun Kumar

Total Post:214

Posted on    December-14-2015 11:53 PM

Normally, you should only connect things to the app delegate if they:
Were created from the same NIB file as the app delegate (static UI elements in single window interfaces)
Are associated with application-level event handling that passes through the app delegate (like the menu item for the Preferences Window)
For everything else, you should create a singleton which manages access to them.

In my programs I normally avoid this, as I think it puts too much responsibility at the top level - I think things should self-manage where possible and that higher level management should only be used when there is a requirement for coordination between peer-level modules.

Don't want to miss updates? Please click the below button!

Follow MindStick