Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to AppDelegate methods from NSViewController

I'm trying to execute a method present in AppDelegate from my NSViewController class. I tried this line to access to the AppDelegate :

let appDelegate = UIApplication.shared.delegate as! AppDelegate;

Without success : Use of unresolved identifier 'UIApplication'. Tried to import UIKit, doesn't works ... cause it's for IOS ?

PS : It's hard to learn how to develop in swift ... a lot of tutorials are for objective C, and the swifts can also be for IOS ...

like image 809
Antoine Avatar asked Jun 10 '26 22:06

Antoine


1 Answers

NSViewController is clearly macOS.

In macOS you get the application delegate with

let appDelegate = NSApp.delegate as! AppDelegate

NSApp is a shortcut for NSApplication.shared

like image 86
vadian Avatar answered Jun 13 '26 12:06

vadian