-1

I've just approached Swift, for building a quick utility app for my MacBook. I have written the following code, but it gives me the error "Cannot find 'UIScreen' in scope".

class AppDelegate: NSObject,NSApplicationDelegate{
    //...
    func applicationDidFinishLaunching(_ notification: Notification) {

        Timer.scheduledTimer(withTimeInterval: 10, repeats: true) { timer in
            UIScreen.mainScreen().brightness = CGFloat(0.0) //<- error here
        }
    }
    //...
}

Initially I thought I've missed an import, but I cannot find what to import (UIKit, is only for iOS). Thank you for any help

1 Answers1

1

Anything beginning with "UI" is an iOS class. Those classes are not available from a macOS app.

The equivalent class for macOS is probably NSScreen, although I don't think it has an exposed brightness property like the one you are trying to set.

Willeke
  • 13,420
  • 4
  • 19
  • 46
Duncan C
  • 122,346
  • 22
  • 162
  • 258