What is the proper way of accessing a method of my application (object implementing UIApplicationDelegate) from anywhere in my code?
Caleb is right, adding a tip below that saves on typing and increases symmetry between AppKit and UIKit.
If you're a Mac programmer you're probably used to accessing the delegate like so,
[NSApp delegate]
In AppKit, NSApp is defined so,
#define NSApp [NSApplication sharedApplication]
So to get something similar in iOS do this,
#define UIApp [UIApplication sharedApplication]
Then to access the delegate you would do this:
[UIApp delegate]
id<UIApplicationDelegate> delegate = [[UIApplication sharedApplication] delegate];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With