Skip to content

Instantly share code, notes, and snippets.

@franckclement
Created October 23, 2018 09:36
Show Gist options
  • Save franckclement/5ee228564effe078f8fc994833341b12 to your computer and use it in GitHub Desktop.
Save franckclement/5ee228564effe078f8fc994833341b12 to your computer and use it in GitHub Desktop.
import MapKit
import RxSwift
import RxCocoa
// Taken from RxCococa until it's exposed public
func castOrThrow<T>(_ resultType: T.Type, _ object: Any) throws -> T {
guard let returnValue = object as? T else {
throw RxCocoaError.castingError(object: object, targetType: resultType)
}
return returnValue
}
extension Reactive where Base: MKLocalSearchCompleter {
public var delegate: DelegateProxy<MKLocalSearchCompleter, MKLocalSearchCompleterDelegate> {
return RxMKLocalSearchCompleterDelegateProxy.proxy(for: base)
}
public var didUpdateResults: ControlEvent<MKLocalSearchCompleter> {
let source = delegate
.methodInvoked(#selector(MKLocalSearchCompleterDelegate.completerDidUpdateResults(_:)))
.map { a in
return try castOrThrow(MKLocalSearchCompleter.self, a[0])
}
return ControlEvent(events: source)
}
public var didFailWithError: ControlEvent<Error> {
let source = delegate
.methodInvoked(#selector(MKLocalSearchCompleterDelegate.completer(_:didFailWithError:)))
.map { a in
return try castOrThrow(Error.self, a[1])
}
return ControlEvent(events: source)
}
public var queryFragment: Binder<String> {
return Binder(self.base) { localSearchCompleter, query in
localSearchCompleter.queryFragment = query
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment