Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Foundation
import AVFoundation
import RxSwift
import RxCocoa
private let associatedkey = UnsafePointer<Void>(malloc(1))
class RxCaptureMetadataOutputObjectsDelegateProxy: DelegateProxy, DelegateProxyType, AVCaptureMetadataOutputObjectsDelegate {
static func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) {
(object as! AVCaptureMetadataOutput)
.setMetadataObjectsDelegate(delegate.map { $0 as! AVCaptureMetadataOutputObjectsDelegate },
queue: objc_getAssociatedObject(object, associatedkey) as! dispatch_queue_t)
}
static func currentDelegateFor(object: AnyObject) -> AnyObject? {
return (object as! AVCaptureMetadataOutput).metadataObjectsDelegate
}
func observeDidOutputMetadataObjects() -> Observable<([AnyObject], AVCaptureConnection)> {
return observe(#selector(AVCaptureMetadataOutputObjectsDelegate.captureOutput(_:didOutputMetadataObjects:fromConnection:)))
.map { ($0[1] as! [AnyObject], $0[2] as! AVCaptureConnection) }
}
}
extension AVCaptureMetadataOutput {
func rx_metadataObjectsDelegate(queue: dispatch_queue_t) -> RxCaptureMetadataOutputObjectsDelegateProxy {
objc_setAssociatedObject(self, associatedkey, queue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
return RxCaptureMetadataOutputObjectsDelegateProxy.proxyForObject(self)
}
}
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.