Skip to content

Instantly share code, notes, and snippets.

@loromits
Last active December 4, 2018 12:51
Show Gist options
  • Save loromits/797ff4eabe9320dfe5ce572f74aec8a7 to your computer and use it in GitHub Desktop.
Save loromits/797ff4eabe9320dfe5ce572f74aec8a7 to your computer and use it in GitHub Desktop.
import Network
extension NWPathMonitor: ReactiveCompatible {}
extension Reactive where Base == NWPathMonitor {
func pathUpdate(on queue: DispatchQueue = .global(qos: .background)) -> Observable<NWPath> {
return Observable.create { [weak base] observer in
base?.pathUpdateHandler = observer.onNext
base?.start(queue: queue)
return Disposables.create { base?.cancel() }
}
}
}
NWPathMonitor(requiredInterfaceType: .cellular).rx.pathUpdate().subscribe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment