在范围内找不到 "UIScreen"
Cannot find "UIScreen" in scope
我刚刚接触 Swift,为我的 MacBook 构建一个快速实用的应用程序。
我写了下面的代码,但它给了我错误“在范围内找不到 'UIScreen'”。
class AppDelegate: NSObject,NSApplicationDelegate{
//...
func applicationDidFinishLaunching(_ notification: Notification) {
Timer.scheduledTimer(withTimeInterval: 10, repeats: true) { timer in
UIScreen.mainScreen().brightness = CGFloat(0.0) //<- error here
}
}
//...
}
最初我以为我错过了导入,但我找不到要导入的内容(UIKit,仅适用于 iOS)。
感谢您的帮助
任何以“UI”开头的都是 iOS class。这些 classes 在 macOS 应用程序中不可用。
macOS 的等效 class 可能是 NSScreen
,尽管我认为它的曝光亮度 属性 不像您要设置的那样。
我刚刚接触 Swift,为我的 MacBook 构建一个快速实用的应用程序。 我写了下面的代码,但它给了我错误“在范围内找不到 'UIScreen'”。
class AppDelegate: NSObject,NSApplicationDelegate{
//...
func applicationDidFinishLaunching(_ notification: Notification) {
Timer.scheduledTimer(withTimeInterval: 10, repeats: true) { timer in
UIScreen.mainScreen().brightness = CGFloat(0.0) //<- error here
}
}
//...
}
最初我以为我错过了导入,但我找不到要导入的内容(UIKit,仅适用于 iOS)。 感谢您的帮助
任何以“UI”开头的都是 iOS class。这些 classes 在 macOS 应用程序中不可用。
macOS 的等效 class 可能是 NSScreen
,尽管我认为它的曝光亮度 属性 不像您要设置的那样。