Reputation: 170758
What is the proper way of accessing a method of my application (object implementing UIApplicationDelegate
) from anywhere in my code?
Upvotes: 2
Views: 2610
Reputation: 4397
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]
Upvotes: 6
Reputation: 125017
id<UIApplicationDelegate> delegate = [[UIApplication sharedApplication] delegate];
Upvotes: 3