How can I get the delegate?
Asked Answered
P

2

12

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?

Phycomycete answered 19/11, 2010 at 6:39 Comment(0)
A
29
AppDelegate *appDelegate = (AppDelegate *)[NSApp delegate];

see the docs for NSApplication for more info.

Ainslie answered 19/11, 2010 at 6:44 Comment(1)
Note that NSApp is really just the same thing as [NSApplication sharedApplication]Chipman
R
2

In Swift 5

let delegate = (NSApplication.shared.delegate) as! AppDelegate
Romeyn answered 1/2, 2020 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.