by
0 9

MKMapView + Rx

Reactive extension for map view
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/2494503/MKMapView---Rx?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
class RxMKMapViewDelegateProxy: DelegateProxy, MKMapViewDelegate, DelegateProxyType { class func currentDelegateFor(_ object: AnyObject) -> AnyObject? { let mapView: MKMapView = (object as? MKMapView)! return mapView.delegate } class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) { let mapView: MKMapView = (object as? MKMapView)! mapView.delegate = delegate as? MKMapViewDelegate } } extension Reactive where Base: MKMapView { public var delegate: DelegateProxy { return RxMKMapViewDelegateProxy.proxyForObject(base) } public func setDelegate(_ delegate: MKMapViewDelegate) -> Disposable { return RxMKMapViewDelegateProxy.installForwardDelegate( delegate, retainDelegate: false, onProxyForObject: self.base ) } var overlays: UIBindingObserver<Base, [MKOverlay]> { return UIBindingObserver(UIElement: self.base) { mapView, overlays in mapView.removeOverlays(mapView.overlays) mapView.addOverlays(overlays) } } public var regionDidChangeAnimated: ControlEvent<Bool> { let source = delegate .methodInvoked(#selector(MKMapViewDelegate.mapView(_:regionDidChangeAnimated:))) .map { parameters in return (parameters[1] as? Bool) ?? false } return ControlEvent(events: source) } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus