Last active
June 7, 2022 21:29
-
-
Save rwbutler/da24d85bc4308dae51bdd1f8a337f873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias ScreenBrightnessPublisher = AnyPublisher<Double, Never> | |
protocol ScreenBrightnessService1 { | |
var publisher: ScreenBrightnessPublisher { get } | |
} | |
class UIKitScreenBrightnessService1: ScreenBrightnessService1 { | |
let publisher: ScreenBrightnessPublisher // i.e. AnyPublisher<Double, Never> | |
init() { | |
publisher = NotificationCenter.default.publisher(for: UIScreen.brightnessDidChangeNotification) | |
.map { _ -> Double in | |
return UIScreen.main.brightness // Swift 5.5 automatically converts between CGFloat and Double. | |
} | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment