diff --git a/RxCocoa/RxCocoa.xcodeproj/project.pbxproj b/RxCocoa/RxCocoa.xcodeproj/project.pbxproj index 67a55c82..81af8cf4 100644 --- a/RxCocoa/RxCocoa.xcodeproj/project.pbxproj +++ b/RxCocoa/RxCocoa.xcodeproj/project.pbxproj @@ -7,6 +7,15 @@ objects = { /* Begin PBXBuildFile section */ + 075F12FF1B4DD075000D7861 /* RxActionSheetDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075F12FC1B4DD075000D7861 /* RxActionSheetDelegateProxy.swift */; }; + 075F13001B4DD075000D7861 /* RxAlertViewDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075F12FD1B4DD075000D7861 /* RxAlertViewDelegateProxy.swift */; }; + 075F13011B4DD075000D7861 /* RxCLLocationManagerDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075F12FE1B4DD075000D7861 /* RxCLLocationManagerDelegateProxy.swift */; }; + 075F13081B4DD100000D7861 /* UIGestureRecognizer+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075F13021B4DD100000D7861 /* UIGestureRecognizer+Rx.swift */; }; + 075F13091B4DD100000D7861 /* UIActionSheet+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075F13031B4DD100000D7861 /* UIActionSheet+Rx.swift */; }; + 075F130A1B4DD100000D7861 /* CLLocationManager+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075F13041B4DD100000D7861 /* CLLocationManager+Rx.swift */; }; + 075F130B1B4DD100000D7861 /* UIAlertView+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075F13051B4DD100000D7861 /* UIAlertView+Rx.swift */; }; + 075F130C1B4DD100000D7861 /* UISegmentedControl+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075F13061B4DD100000D7861 /* UISegmentedControl+Rx.swift */; }; + 075F130D1B4DD100000D7861 /* UISwitch+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075F13071B4DD100000D7861 /* UISwitch+Rx.swift */; }; 493693671B173C8F006FA450 /* UISlider+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 493693661B173C8F006FA450 /* UISlider+Rx.swift */; }; 653C8BF41B114EB600983087 /* UIControl+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653C8BF31B114EB600983087 /* UIControl+Rx.swift */; }; C8092BBB1AF50436008D9A2C /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8092BBA1AF50436008D9A2C /* CoreData.framework */; }; @@ -17,7 +26,7 @@ C81553E41A98AB4A00C63152 /* RxCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = C81553E31A98AB4A00C63152 /* RxCocoa.h */; settings = {ATTRIBUTES = (Public, ); }; }; C83111711B491C9F001F3D67 /* KVOObservable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83111701B491C9F001F3D67 /* KVOObservable.swift */; }; C83111721B491C9F001F3D67 /* KVOObservable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83111701B491C9F001F3D67 /* KVOObservable.swift */; }; - C83225451B1A9ACC0048EC77 /* UIBarButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83225441B1A9ACC0048EC77 /* UIBarButtonItem.swift */; }; + C83225451B1A9ACC0048EC77 /* UIBarButtonItem+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83225441B1A9ACC0048EC77 /* UIBarButtonItem+Rx.swift */; }; C83225471B1A9CCB0048EC77 /* UIDatePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83225461B1A9CCB0048EC77 /* UIDatePicker.swift */; }; C83225491B1A9ECC0048EC77 /* NSControl+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83225481B1A9ECC0048EC77 /* NSControl+Rx.swift */; }; C83CF8631B3DDD54001359E7 /* RxTableViewReactiveArrayDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83CF8621B3DDD54001359E7 /* RxTableViewReactiveArrayDataSource.swift */; }; @@ -68,6 +77,15 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 075F12FC1B4DD075000D7861 /* RxActionSheetDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxActionSheetDelegateProxy.swift; sourceTree = ""; }; + 075F12FD1B4DD075000D7861 /* RxAlertViewDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxAlertViewDelegateProxy.swift; sourceTree = ""; }; + 075F12FE1B4DD075000D7861 /* RxCLLocationManagerDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxCLLocationManagerDelegateProxy.swift; sourceTree = ""; }; + 075F13021B4DD100000D7861 /* UIGestureRecognizer+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIGestureRecognizer+Rx.swift"; sourceTree = ""; }; + 075F13031B4DD100000D7861 /* UIActionSheet+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIActionSheet+Rx.swift"; sourceTree = ""; }; + 075F13041B4DD100000D7861 /* CLLocationManager+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CLLocationManager+Rx.swift"; sourceTree = ""; }; + 075F13051B4DD100000D7861 /* UIAlertView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertView+Rx.swift"; sourceTree = ""; }; + 075F13061B4DD100000D7861 /* UISegmentedControl+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UISegmentedControl+Rx.swift"; sourceTree = ""; }; + 075F13071B4DD100000D7861 /* UISwitch+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UISwitch+Rx.swift"; sourceTree = ""; }; 493693661B173C8F006FA450 /* UISlider+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UISlider+Rx.swift"; sourceTree = ""; }; 653C8BF31B114EB600983087 /* UIControl+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIControl+Rx.swift"; sourceTree = ""; }; C8092BBA1AF50436008D9A2C /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; @@ -78,7 +96,7 @@ C81553E21A98AB4A00C63152 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C81553E31A98AB4A00C63152 /* RxCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RxCocoa.h; sourceTree = ""; }; C83111701B491C9F001F3D67 /* KVOObservable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KVOObservable.swift; sourceTree = ""; }; - C83225441B1A9ACC0048EC77 /* UIBarButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIBarButtonItem.swift; sourceTree = ""; }; + C83225441B1A9ACC0048EC77 /* UIBarButtonItem+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+Rx.swift"; sourceTree = ""; }; C83225461B1A9CCB0048EC77 /* UIDatePicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIDatePicker.swift; sourceTree = ""; }; C83225481B1A9ECC0048EC77 /* NSControl+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSControl+Rx.swift"; sourceTree = ""; }; C83CF8621B3DDD54001359E7 /* RxTableViewReactiveArrayDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxTableViewReactiveArrayDataSource.swift; sourceTree = ""; }; @@ -195,6 +213,9 @@ C84969C81B47DE1D00E0BDB9 /* RxTableViewDataSourceProxy.swift */, C84969C91B47DE1D00E0BDB9 /* RxTableViewDelegateProxy.swift */, C813F95C1B48799200620334 /* RxSeachBarDelegateProxy.swift */, + 075F12FC1B4DD075000D7861 /* RxActionSheetDelegateProxy.swift */, + 075F12FD1B4DD075000D7861 /* RxAlertViewDelegateProxy.swift */, + 075F12FE1B4DD075000D7861 /* RxCLLocationManagerDelegateProxy.swift */, ); path = Proxies; sourceTree = ""; @@ -250,7 +271,7 @@ C862824D1B370C7E00500DC3 /* Events */, C86282491B3607D500500DC3 /* CoreDataEntityEvent.swift */, C80B56211B2DFCA0008F915D /* NSManagedObjectContext+Rx.swift */, - C83225441B1A9ACC0048EC77 /* UIBarButtonItem.swift */, + C83225441B1A9ACC0048EC77 /* UIBarButtonItem+Rx.swift */, C88BB8E01B07F2BE0064D411 /* UIButton+Rx.swift */, C88BB8E11B07F2BE0064D411 /* UICollectionView+Rx.swift */, 653C8BF31B114EB600983087 /* UIControl+Rx.swift */, @@ -262,6 +283,12 @@ 493693661B173C8F006FA450 /* UISlider+Rx.swift */, C88BB8E61B07F2BE0064D411 /* UITableView+Rx.swift */, C88BB8E71B07F2BE0064D411 /* UITextField+Rx.swift */, + 075F13021B4DD100000D7861 /* UIGestureRecognizer+Rx.swift */, + 075F13031B4DD100000D7861 /* UIActionSheet+Rx.swift */, + 075F13041B4DD100000D7861 /* CLLocationManager+Rx.swift */, + 075F13051B4DD100000D7861 /* UIAlertView+Rx.swift */, + 075F13061B4DD100000D7861 /* UISegmentedControl+Rx.swift */, + 075F13071B4DD100000D7861 /* UISwitch+Rx.swift */, ); path = iOS; sourceTree = ""; @@ -421,17 +448,24 @@ C84969CE1B47DE1D00E0BDB9 /* RxTableViewDelegateProxy.swift in Sources */, C86282501B370C7E00500DC3 /* ItemEvents.swift in Sources */, C83225471B1A9CCB0048EC77 /* UIDatePicker.swift in Sources */, - C83225451B1A9ACC0048EC77 /* UIBarButtonItem.swift in Sources */, + C83225451B1A9ACC0048EC77 /* UIBarButtonItem+Rx.swift in Sources */, + 075F130C1B4DD100000D7861 /* UISegmentedControl+Rx.swift in Sources */, + 075F13001B4DD075000D7861 /* RxAlertViewDelegateProxy.swift in Sources */, + 075F130D1B4DD100000D7861 /* UISwitch+Rx.swift in Sources */, C83CF8631B3DDD54001359E7 /* RxTableViewReactiveArrayDataSource.swift in Sources */, C84969CB1B47DE1D00E0BDB9 /* RxCollectionViewDelegateProxy.swift in Sources */, C84969CC1B47DE1D00E0BDB9 /* RxScrollViewDelegateProxy.swift in Sources */, C88BB8E81B07F2BE0064D411 /* UIButton+Rx.swift in Sources */, C8633AB41B093EDF00375D60 /* Logging.swift in Sources */, + 075F13011B4DD075000D7861 /* RxCLLocationManagerDelegateProxy.swift in Sources */, C813F95D1B48799200620334 /* RxSeachBarDelegateProxy.swift in Sources */, + 075F13091B4DD100000D7861 /* UIActionSheet+Rx.swift in Sources */, C862823F1B36037100500DC3 /* NSURLSession+Rx.swift in Sources */, C88BB8EB1B07F2BE0064D411 /* UILabel+Rx.swift in Sources */, C80B56221B2DFCA0008F915D /* NSManagedObjectContext+Rx.swift in Sources */, + 075F130A1B4DD100000D7861 /* CLLocationManager+Rx.swift in Sources */, C88BB8E91B07F2BE0064D411 /* UICollectionView+Rx.swift in Sources */, + 075F130B1B4DD100000D7861 /* UIAlertView+Rx.swift in Sources */, C862824A1B3607D500500DC3 /* CoreDataEntityEvent.swift in Sources */, C84969CD1B47DE1D00E0BDB9 /* RxTableViewDataSourceProxy.swift in Sources */, C8633ABA1B093EDF00375D60 /* RxCocoa.swift in Sources */, @@ -441,11 +475,13 @@ C83111711B491C9F001F3D67 /* KVOObservable.swift in Sources */, C88BB8EC1B07F2BE0064D411 /* UIScrollView+Rx.swift in Sources */, C84969CA1B47DE1D00E0BDB9 /* RxCollectionViewDataSourceProxy.swift in Sources */, + 075F12FF1B4DD075000D7861 /* RxActionSheetDelegateProxy.swift in Sources */, C80B562B1B2E242D008F915D /* DelegateProxy.swift in Sources */, 653C8BF41B114EB600983087 /* UIControl+Rx.swift in Sources */, C8A57F881B41530A00D5570A /* RxCollectionViewReactiveArrayDataSource.swift in Sources */, C8AED7E91B3CC93600678DDE /* RxTableViewDataSourceType.swift in Sources */, C8D95C171B2F0CD700FA661F /* DelegateProxyType.swift in Sources */, + 075F13081B4DD100000D7861 /* UIGestureRecognizer+Rx.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/RxCocoa/RxCocoa/iOS/CLLocationManager+Rx.swift b/RxCocoa/RxCocoa/iOS/CLLocationManager+Rx.swift new file mode 100644 index 00000000..86158052 --- /dev/null +++ b/RxCocoa/RxCocoa/iOS/CLLocationManager+Rx.swift @@ -0,0 +1,148 @@ +// +// CLLocationManager+Rx.swift +// RxCocoa +// +// Created by Carlos García on 8/7/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import UIKit +import CoreLocation +import RxSwift + + +extension CLLocationManager { + + public var rx_delegate: DelegateProxy { + return proxyForObject(self) as RxCLLocationManagerDelegateProxy + } + + // MARK: Responding to Location Events + + public var rx_didUpdateLocations: Observable<[AnyObject]> { + return rx_delegate.observe("locationManager:didUpdateLocations:") + >- map { a in + return a[1] as! [AnyObject] + } + } + + public var rx_didFailWithError: Observable { + return rx_delegate.observe("locationManager:didFailWithError:") + >- map { a in + return a[1] as! NSError + } + } + + public var rx_didFinishDeferredUpdatesWithError: Observable { + return rx_delegate.observe("locationManager:didFinishDeferredUpdatesWithError:") + >- map { a in + return a[1] as! NSError + } + } + + // MARK: Pausing Location Updates + + public var rx_didPauseLocationUpdates: Observable { + return rx_delegate.observe("locationManagerDidPauseLocationUpdates:") + >- map { a in + return Void() + } + } + + public var rx_didResumeLocationUpdates: Observable { + return rx_delegate.observe("locationManagerDidResumeLocationUpdates:") + >- map { a in + return Void() + } + } + + // MARK: Responding to Heading Events + + public var rx_didUpdateHeading: Observable { + return rx_delegate.observe("locationManager:didUpdateHeading:") + >- map { a in + return a[1] as! CLHeading + } + } + + public var rx_shouldDisplayHeadingCalibration: Observable { + return rx_delegate.observe("locationManagerShouldDisplayHeadingCalibration:") + >- map { a in + return Void() + } + } + + // MARK: Responding to Region Events + + public var rx_didEnterRegion: Observable { + return rx_delegate.observe("locationManager:didEnterRegion:") + >- map { a in + return a[1] as! CLRegion + } + } + + public var rx_didExitRegion: Observable { + return rx_delegate.observe("locationManager:didExitRegion:") + >- map { a in + return a[1] as! CLRegion + } + } + + public var rx_didDetermineStateForRegion: Observable<(state: CLRegionState, region: CLRegion)> { + return rx_delegate.observe("locationManager:didDetermineState:forRegion:") + >- map { a in + return (state: a[1] as! CLRegionState, region: a[2] as! CLRegion) + } + } + + public var rx_monitoringDidFailForRegionWithError: Observable<(region: CLRegion, error: NSError)> { + return rx_delegate.observe("locationManager:monitoringDidFailForRegion:withError:") + >- map { a in + return (region: a[1] as! CLRegion, error: a[2] as! NSError) + } + } + + public var rx_didStartMonitoringForRegion: Observable { + return rx_delegate.observe("locationManager:didStartMonitoringForRegion:") + >- map { a in + return a[1] as! CLRegion + } + } + + // MARK: Responding to Ranging Events + + public var rx_didRangeBeaconsInRegion: Observable<(beacons: [AnyObject], region: CLBeaconRegion)> { + return rx_delegate.observe("locationManager:didRangeBeacons:inRegion:") + >- map { a in + return (beacons: a[1] as! [AnyObject], region: a[2] as! CLBeaconRegion) + } + } + + public var rx_rangingBeaconsDidFailForRegionWithError: Observable<(region: CLBeaconRegion, error: NSError)> { + return rx_delegate.observe("locationManager:rangingBeaconsDidFailForRegion:withError:") + >- map { a in + return (region: a[1] as! CLBeaconRegion, error: a[2] as! NSError) + } + } + + // MARK: Responding to Visit Events + + public var rx_didVisit: Observable { + return rx_delegate.observe("locationManager:didVisit:") + >- map { a in + return a[1] as! CLVisit + } + } + + // MARK: Responding to Authorization Changes + + public var rx_didChangeAuthorizationStatus: Observable { + return rx_delegate.observe("locationManager:didChangeAuthorizationStatus:") + >- map { a in + return a[1] as! CLAuthorizationStatus + } + } + + + +} diff --git a/RxCocoa/RxCocoa/iOS/Proxies/RxActionSheetDelegateProxy.swift b/RxCocoa/RxCocoa/iOS/Proxies/RxActionSheetDelegateProxy.swift new file mode 100644 index 00000000..e743fb32 --- /dev/null +++ b/RxCocoa/RxCocoa/iOS/Proxies/RxActionSheetDelegateProxy.swift @@ -0,0 +1,25 @@ +// +// RxActionSheetDelegateProxy.swift +// RxCocoa +// +// Created by Carlos García on 8/7/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import UIKit +import RxSwift + +class RxActionSheetDelegateProxy : DelegateProxy + , UIActionSheetDelegate + , DelegateProxyType { + + class func currentDelegateFor(object: AnyObject) -> AnyObject? { + let actionSheet: UIActionSheet = castOrFatalError(object) + return actionSheet.delegate + } + + class func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) { + let actionSheet: UIActionSheet = castOrFatalError(object) + actionSheet.delegate = castOptionalOrFatalError(delegate) + } +} diff --git a/RxCocoa/RxCocoa/iOS/Proxies/RxAlertViewDelegateProxy.swift b/RxCocoa/RxCocoa/iOS/Proxies/RxAlertViewDelegateProxy.swift new file mode 100644 index 00000000..4d45fe0f --- /dev/null +++ b/RxCocoa/RxCocoa/iOS/Proxies/RxAlertViewDelegateProxy.swift @@ -0,0 +1,25 @@ +// +// RxAlertViewDelegateProxy.swift +// RxCocoa +// +// Created by Carlos García on 8/7/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import UIKit +import RxSwift + +class RxAlertViewDelegateProxy : DelegateProxy + , UIAlertViewDelegate + , DelegateProxyType { + + class func currentDelegateFor(object: AnyObject) -> AnyObject? { + let alertView: UIAlertView = castOrFatalError(object) + return alertView.delegate + } + + class func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) { + let alertView: UIAlertView = castOrFatalError(object) + alertView.delegate = castOptionalOrFatalError(delegate) + } +} diff --git a/RxCocoa/RxCocoa/iOS/Proxies/RxCLLocationManagerDelegateProxy.swift b/RxCocoa/RxCocoa/iOS/Proxies/RxCLLocationManagerDelegateProxy.swift new file mode 100644 index 00000000..f0291489 --- /dev/null +++ b/RxCocoa/RxCocoa/iOS/Proxies/RxCLLocationManagerDelegateProxy.swift @@ -0,0 +1,26 @@ +// +// RxCLLocationManagerDelegateProxy.swift +// RxCocoa +// +// Created by Carlos García on 8/7/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import UIKit +import CoreLocation +import RxSwift + +class RxCLLocationManagerDelegateProxy : DelegateProxy + , CLLocationManagerDelegate + , DelegateProxyType { + + class func currentDelegateFor(object: AnyObject) -> AnyObject? { + let locationManager: CLLocationManager = castOrFatalError(object) + return locationManager.delegate + } + + class func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) { + let locationManager: CLLocationManager = castOrFatalError(object) + locationManager.delegate = castOptionalOrFatalError(delegate) + } +} diff --git a/RxCocoa/RxCocoa/iOS/UIActionSheet+Rx.swift b/RxCocoa/RxCocoa/iOS/UIActionSheet+Rx.swift new file mode 100644 index 00000000..b07fa049 --- /dev/null +++ b/RxCocoa/RxCocoa/iOS/UIActionSheet+Rx.swift @@ -0,0 +1,39 @@ +// +// UIActionSheet+Rx.swift +// RxCocoa +// +// Created by Carlos García on 8/7/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import UIKit +import RxSwift + + +extension UIActionSheet { + + public var rx_delegate: DelegateProxy { + return proxyForObject(self) as RxActionSheetDelegateProxy + } + + public var rx_clickedButtonAtIndex: Observable { + return rx_delegate.observe("actionSheet:clickedButtonAtIndex:") + >- map { a in + return a[1] as! Int + } + } + + public var rx_willDismissWithButtonIndex: Observable { + return rx_delegate.observe("actionSheet:willDismissWithButtonIndex:") + >- map { a in + return a[1] as! Int + } + } + + public var rx_didDismissWithButtonIndex: Observable { + return rx_delegate.observe("actionSheet:didDismissWithButtonIndex:") + >- map { a in + return a[1] as! Int + } + } +} \ No newline at end of file diff --git a/RxCocoa/RxCocoa/iOS/UIAlertView+Rx.swift b/RxCocoa/RxCocoa/iOS/UIAlertView+Rx.swift new file mode 100644 index 00000000..65db3525 --- /dev/null +++ b/RxCocoa/RxCocoa/iOS/UIAlertView+Rx.swift @@ -0,0 +1,39 @@ +// +// UIAlertView+Rx.swift +// RxCocoa +// +// Created by Carlos García on 8/7/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import UIKit +import RxSwift + + +extension UIAlertView { + + public var rx_delegate: DelegateProxy { + return proxyForObject(self) as RxAlertViewDelegateProxy + } + + public var rx_clickedButtonAtIndex: Observable { + return rx_delegate.observe("alertView:clickedButtonAtIndex:") + >- map { a in + return a[1] as! Int + } + } + + public var rx_willDismissWithButtonIndex: Observable { + return rx_delegate.observe("alertView:willDismissWithButtonIndex:") + >- map { a in + return a[1] as! Int + } + } + + public var rx_didDismissWithButtonIndex: Observable { + return rx_delegate.observe("alertView:didDismissWithButtonIndex:") + >- map { a in + return a[1] as! Int + } + } +} diff --git a/RxCocoa/RxCocoa/iOS/UIBarButtonItem.swift b/RxCocoa/RxCocoa/iOS/UIBarButtonItem+Rx.swift similarity index 100% rename from RxCocoa/RxCocoa/iOS/UIBarButtonItem.swift rename to RxCocoa/RxCocoa/iOS/UIBarButtonItem+Rx.swift diff --git a/RxCocoa/RxCocoa/iOS/UIGestureRecognizer+Rx.swift b/RxCocoa/RxCocoa/iOS/UIGestureRecognizer+Rx.swift new file mode 100644 index 00000000..26d066a1 --- /dev/null +++ b/RxCocoa/RxCocoa/iOS/UIGestureRecognizer+Rx.swift @@ -0,0 +1,71 @@ +// +// UIGestureRecognizer+Rx.swift +// Touches +// +// Created by Carlos García on 10/6/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import UIKit +import RxSwift + + + + +// This should be only used from `MainScheduler` +class GestureTarget: NSObject, Disposable { + typealias Callback = (UIGestureRecognizer) -> Void + + let selector = Selector("eventHandler:") + + let gestureRecognizer: UIGestureRecognizer + var callback: Callback? + + init(_ gestureRecognizer: UIGestureRecognizer, callback: Callback) { + self.gestureRecognizer = gestureRecognizer + self.callback = callback + + super.init() + + gestureRecognizer.addTarget(self, action: selector) + + let method = self.methodForSelector(selector) + if method == nil { + fatalError("Can't find method") + } + } + + func eventHandler(sender: UIGestureRecognizer!) { + if let callback = self.callback { + callback(self.gestureRecognizer) + } + } + + func dispose() { + MainScheduler.ensureExecutingOnScheduler() + + self.gestureRecognizer.removeTarget(self, action: self.selector) + self.callback = nil + } + + deinit { + dispose() + } +} + +extension UIGestureRecognizer { + + public var rx_event: Observable { + return AnonymousObservable { observer in + MainScheduler.ensureExecutingOnScheduler() + + let observer = GestureTarget(self) { + control in + sendNext(observer, self) + } + + return observer + } + } + +} \ No newline at end of file diff --git a/RxCocoa/RxCocoa/iOS/UISegmentedControl+Rx.swift b/RxCocoa/RxCocoa/iOS/UISegmentedControl+Rx.swift new file mode 100644 index 00000000..e200b21c --- /dev/null +++ b/RxCocoa/RxCocoa/iOS/UISegmentedControl+Rx.swift @@ -0,0 +1,30 @@ +// +// UISegmentedControl+Rx.swift +// RxCocoa +// +// Created by Carlos García on 8/7/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import UIKit +import RxSwift + + +extension UISegmentedControl { + + public var rx_value: Observable { + return AnonymousObservable { observer in + + sendNext(observer, self.selectedSegmentIndex) + + let controlTarget = ControlTarget(control: self, controlEvents: UIControlEvents.ValueChanged) { control in + sendNext(observer, (control as! UISegmentedControl).selectedSegmentIndex) + } + + return AnonymousDisposable { + controlTarget.dispose() + } + } + } + +} \ No newline at end of file diff --git a/RxCocoa/RxCocoa/iOS/UISwitch+Rx.swift b/RxCocoa/RxCocoa/iOS/UISwitch+Rx.swift new file mode 100644 index 00000000..5e1f6763 --- /dev/null +++ b/RxCocoa/RxCocoa/iOS/UISwitch+Rx.swift @@ -0,0 +1,30 @@ +// +// UISwitch+Rx.swift +// RxCocoa +// +// Created by Carlos García on 8/7/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import UIKit +import RxSwift + + +extension UISwitch { + + public var rx_value: Observable { + return AnonymousObservable { observer in + + sendNext(observer, self.on) + + let controlTarget = ControlTarget(control: self, controlEvents: UIControlEvents.ValueChanged) { control in + sendNext(observer, (control as! UISwitch).on) + } + + return AnonymousDisposable { + controlTarget.dispose() + } + } + } + +} \ No newline at end of file