Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 219
zeusmain Avatar asked Nov 19 '10 06:11

zeusmain


2 Answers

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

see the docs for NSApplication for more info.

like image 57
superfell Avatar answered Sep 17 '22 11:09

superfell


In Swift 5

let delegate = (NSApplication.shared.delegate) as! AppDelegate
like image 39
Bezaleel Avatar answered Sep 21 '22 11:09

Bezaleel