ZBarSDK is the only place I've ever seen NSFastEnumeration
. I don't know a whole lot about it, nor do I know exactly why ZBarSDK was designed to be used in this way.
NSFastEnumeration
isn't any faster than using a forin
loop. It is faster than a regular for
or while
(or do-while
) loop, but not faster than a forin
.
In a forin
loop, we're using regular Objective-C collections, and NSArray
has a firstObject
and lastObject
.
But if the real question is (and should be) how do I improve this code (more than just specifically grabbing a single object out of an NSFastEnumeration
), then the answer is to use AVCaptureMetadataOutput (official documentation), which was introduced in iOS7.
ZBarSDK has an iOS7 memory leak. Also, I don't know about compiled on-device size, but when I removed it from my project, it saved about 1.4mb from the project size.
Meanwhile, AVCaptureMetadataOutput
has many advantages over ZBarSDK
.
- It's slightly easier to use... and it's simple to use if you're already familiar with video capture in iOS.
- It leaves a smaller footprint in terms of storage space your app takes up on a device.
- Even without ZBarSDK's memory leak,
AVCaptureMetadataOutput
has a smaller memory footprint.
AVCaptureMetadataOutput
seems to scan barcodes faster and a farther distances than what I could manage with ZBarSDK
.
- ZBarSDK doesn't support 64-bit processors at all.
AVCaptureMetadataOutput
however does.
break;
command in the loop, then it selects the first symbol. \$\endgroup\$