Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
}
}
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
You can’t perform that action at this time.