objective c - How to access properties on AppDelegate from classes owned by it? -
i'm writing simple os x app far structured so:
- the main business logic in
appdelegate.m - there 2
viewcontrollersxibsappdelegateowns , presents in window
i need access properties on appdelegate viewcontrollers, i'm doing this:
appdelegate *delegate = (appdelegate *)[[nsapplication sharedapplication] delegate]; delegate.someproperty = somevalue; this "feels" hacky. proper pattern or dumb?
two alternative architectures came were:
- to use delegation , define kind of "ui delegate" protocol in vcs , make appdelegate conform it
- to have vcs post notifications appdelegate listens to
the first feels tangled , dirty, second feels unreliable.
what proper pattern here? how should vcs owned appdelegate access properties?
try this
appdelegate *app = [nsapp delegate]; instead of this
appdelegate *delegate = (appdelegate *)[[nsapplication sharedapplication] delegate];
Comments
Post a Comment