IN OBJECTIVE-C PROPER USE OF APPLICATION DELEGATE

Nigel Bunyan

Total Post:20

Points:140
Posted by  Nigel Bunyan
 444  View(s)
Ratings:
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.

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: In Objective-C proper use of Application delegate

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!