#How to use ZbarSDK in Swift(XCode 6.2, base SDK iOS 8.2)
##Steps
- Download ZbarSDK and drag ZbarSDK folder in Swift project, setup buiding settings according to the zBarSDK tutorial
- Add #import "ZBarSDK.h" in YourApp_Bridging_Header file
- In your ViewController add ZBarReaderDelegate, setup ZBarReader, receive barcode data
##Posible building issues:
- Missing required architecture arm64 in file ...
Reason: the libzbar.a is not compiled to arm64 architecture
Solution: download libzbar.a compiled for arm64, and replace the libzbar.a in your project download link: (https://www.dropbox.com/sh/xoo1ql3yxzmu6wz/lV8vJFqJCE)
import UIKit
//This extension is used for the "for symbol in results as ZBarSymbolSet"
extension ZBarSymbolSet: SequenceType {
public func generate() -> NSFastGenerator {
return NSFastGenerator(self)
}
}
class MyViewController: UIViewController, UITextFieldDelegate, ZBarReaderDelegate {
var ZBarReader: ZBarReaderViewController?
@IBOutlet var barCodeText: UITextField!
@IBAction func scanAction(sender: AnyObject) {
if (self.ZBarReader == nil) {
self.ZBarReader = ZBarReaderViewController()
}
self.ZBarReader?.readerDelegate = self
self.ZBarReader?.scanner.setSymbology(ZBAR_UPCA, config: ZBAR_CFG_ENABLE, to: 1)
self.ZBarReader?.readerView.zoom = 1.0
self.ZBarReader?.modalInPopover = false
self.ZBarReader?.showsZBarControls = false
navigationController?.pushViewController(self.ZBarReader!, animated:true)
}
override func viewDidLoad() {
super.viewDidLoad()
self.barCodeText.delegate = self
}
func imagePickerController(reader:UIImagePickerController,
didFinishPickingMediaWithInfo info: NSDictionary) {
// ADD: get the decode results
var results: NSFastEnumeration = info.objectForKey(ZBarReaderControllerResults) as NSFastEnumeration
var symbolFound : ZBarSymbol?
for symbol in results as ZBarSymbolSet {
symbolFound = symbol as? ZBarSymbol
break
}
var resultString = NSString(string: symbolFound!.data)
self.barCodeText.text = resultString //set barCode
navigationController?.popViewControllerAnimated(true)
}
}
Hi,
I am installed pod version 1.3 for ZbarSdk and integrate your code in app. But I am facing build error issue in below line of code.
extension ZBarSymbolSet: SequenceType { // Error Type ZBarSymbolSet does not conform to protocol 'Sequence'
public func generate() -> NSFastGenerator { // Use of undeclared type 'NSFastGenerator'
func imagePickerController(reader:UIImagePickerController,
didFinishPickingMediaWithInfo info: NSDictionary) // its give me warning
for symbol in results as ZBarSymbolSet // Cannot convert value of type 'NSFastEnumeration' to type 'ZBarSymbolSet' in coercion.
All error are raised while build the app in Xcode 8.1. So please suggest or any idea for this. Your help will be me appreciate me.
Thanks
Nikunj Jadav