3

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 ...

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
Antoine
  • 135
  • 5

1 Answers1

9

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

vadian
  • 274,689
  • 30
  • 353
  • 361