zeusmain
zeusmain

Reputation: 121

How can I get the delegate?

In iOS to get the delegate I use following code:

AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication] delegate];

How to get the delegate in Cocoa Mac programming?

Upvotes: 12

Views: 6873

Answers (2)

Bezaleel
Bezaleel

Reputation: 304

In Swift 5

let delegate = (NSApplication.shared.delegate) as! AppDelegate

Upvotes: 2

superfell
superfell

Reputation: 19040

AppDelegate *appDelegate = (AppDelegate *)[NSApp delegate];

see the docs for NSApplication for more info.

Upvotes: 29

Related Questions