ios - How to provide view controllers with pointer to already-initialized singleton object? -


after initializing singleton object via -[appdelegate didfinishlaunchingwithoptions?], how 1 pass pointer of object view controller?

it helps, let's assume object stand-alone reasonably coupled ui. (for example, managing server connection thread.) prefer more "intimate" signaling via nsnotificationcenter.

it depends.

if object needed single view controller, initialize in viewdidload. if is needed entire app, initialize in app delegate.

in case, best in app delegate since needed lifetime of application , not used 1 view controller.

you can create property in app delegate , put object in it. can delegate anywhere in application this:

((appdelegate *)[uiapplication sharedapplication].delegate) 

so, long have #imported appdelegate.h in file accessing app delegate from, can object this:

myobject *object = ((appdelegate *)[uiapplication sharedapplication].delegate).propertyname; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -