Skip to content

Instantly share code, notes, and snippets.

@rwbutler
Last active June 7, 2022 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwbutler/da24d85bc4308dae51bdd1f8a337f873 to your computer and use it in GitHub Desktop.
Save rwbutler/da24d85bc4308dae51bdd1f8a337f873 to your computer and use it in GitHub Desktop.
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