Last active
March 10, 2016 17:22
-
-
Save chuganzy/40db6906a546bf2ef91b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import AVFoundation | |
import RxSwift | |
import RxCocoa | |
extension AVCaptureSession { | |
var rx_runnning: AnyObserver<Bool> { | |
return RxBindingObserver(element: self) { element, value in | |
if value { | |
element.startRunning() | |
} else { | |
element.stopRunning() | |
} | |
}.asObserver() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import RxSwift | |
class RxBindingObserver<Element: AnyObject, E> : ObserverType { | |
private weak var _element: Element? | |
private let _binding: (Element, E) -> Void | |
init(element: Element, binding: (Element, E) -> Void) { | |
_element = element | |
_binding = binding | |
} | |
func on(event: Event<E>) { | |
switch event { | |
case .Next(let value): | |
if let element = _element { | |
_binding(element, value) | |
} | |
default: | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment