Skip to content

Instantly share code, notes, and snippets.

@alkozin
Last active July 6, 2022 05:17
Show Gist options
  • Save alkozin/eacac508ba917936c9dfec24907c52b7 to your computer and use it in GitHub Desktop.
Save alkozin/eacac508ba917936c9dfec24907c52b7 to your computer and use it in GitHub Desktop.
//Look to geolocation permissions request to illustrate.
//Request is constructed according to `with` object
//
//Ask always permissions only if `ask` `with` `CLAuthorizationStatus.authorizedAlways` input argument
//Otherwise `ask` only in use permissions
//
extension CLAuthorizationStatus: Asking {
static func ask<E>(with: Any?, in pipe: Pipe, expect: Expect<E>) {
let source = with as? CLLocationManager ?? pipe.get()
switch with as? CLAuthorizationStatus {
case .authorizedAlways:
source.requestAlwaysAuthorization()
case .authorizedWhenInUse, .none:
source.requestWhenInUseAuthorization()
default:
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment