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
Post a Comment