Skip to content

Instantly share code, notes, and snippets.

@Qata
Last active August 29, 2015 14:21
Show Gist options
  • Save Qata/dd32d581de555998f77d to your computer and use it in GitHub Desktop.
Save Qata/dd32d581de555998f77d to your computer and use it in GitHub Desktop.
- (RACSignal *)rac_capturedMetadataObjectsSignal
{
[self setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
RACSignal *signal = objc_getAssociatedObject(self, _cmd);
if (signal != nil) return signal;
signal = [[[[self rac_signalForSelector:@selector(captureOutput:didOutputMetadataObjects:fromConnection:) fromProtocol:@protocol(AVCaptureMetadataOutputObjectsDelegate)] reduceEach:^id(AVCaptureOutput * output, NSArray * objects, AVCaptureConnection * connection){
return objects;
}] filter:^BOOL(NSArray * objects) {
return objects.count;
}] map:^id(NSArray * objects) {
return objects.firstObject;
}];
objc_setAssociatedObject(self, _cmd, signal, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return signal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment