title: iOS Swift Scanning Multiple Barcodes
body: <p>I use the following code to scan barcodes:</p>
  
  <pre><code>func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {
  
      var highlightViewRect = CGRectZero
  
      var barCodeObject : AVMetadataObject!
  
      var detectionString : String!
  
      let barCodeTypes = [AVMetadataObjectTypeUPCECode,
          AVMetadataObjectTypeCode39Code,
          AVMetadataObjectTypeCode39Mod43Code,
          AVMetadataObjectTypeEAN13Code,
          AVMetadataObjectTypeEAN8Code,
          AVMetadataObjectTypeCode93Code,
          AVMetadataObjectTypeCode128Code,
          AVMetadataObjectTypePDF417Code,
          AVMetadataObjectTypeQRCode,
          AVMetadataObjectTypeAztecCode
      ]
  
  
      // The scanner is capable of capturing multiple 2-dimensional barcodes in one scan.
  
      for metadata in metadataObjects {
          for barcodeType in barCodeTypes {
  
              if metadata.type == barcodeType {
                  barCodeObject = self.previewLayer.transformedMetadataObjectForMetadataObject(metadata as! AVMetadataMachineReadableCodeObject)
  
                  highlightViewRect = barCodeObject.bounds
  
                  detectionString = (metadata as! AVMetadataMachineReadableCodeObject).stringValue
  
                  let len = detectionString.characters.count
                  print("raw=\(detectionString)")
                  if len == 25 {
                      detectionString=detectionString.substringWithRange(Range&lt;String.Index&gt;(start: detectionString.startIndex.advancedBy(3), end: detectionString.endIndex.advancedBy(0)))
                  } else if len &gt; 22 {
                      detectionString=detectionString.substringWithRange(Range&lt;String.Index&gt;(start: detectionString.startIndex.advancedBy(22), end: detectionString.endIndex.advancedBy(0)))
                  }
                  print("mod=\(detectionString)")
              }
  
          }
      }
  
      self.session.stopRunning()
      sendScan(detectionString)
  
      self.highlightView.frame = highlightViewRect
      self.view.bringSubviewToFront(self.highlightView)
  
  }
  </code></pre>
  
  <p>It looks like it should capture multiple barcodes from the same scan.  However, it only captures one.  I'm sure I'm doing something wrong here but I'm not sure what.</p>