Skip to content

Instantly share code, notes, and snippets.

@robertmryan
Created August 9, 2025 05:00
Show Gist options
  • Select an option

  • Save robertmryan/a8b38a571e88e9b74886953d210998bc to your computer and use it in GitHub Desktop.

Select an option

Save robertmryan/a8b38a571e88e9b74886953d210998bc to your computer and use it in GitHub Desktop.
func createDefaultPublisher() -> AnyPublisher<Float, Never> {
UIDevice.batteryLevelDidChangeNotification
.publisher
.compactMap { $0.object as? UIDevice }
.receive(on: DispatchQueue.main)
.map { $0.batteryLevel }
.eraseToAnyPublisher()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment