I'm a newbie with Ios. i'm learning swift and overlooked object c.
Currently, i'm writing an demo with swift and xcode 6.1 which can scan qrcode and barcode from camera or an image from image library.
I know that AVFoundation framework support scanning qrcode and barcode, but it can only scan from camera.
I searched and found zbarSDK which support scan code from camera and image. I do as instructions in http://zbar.sourceforge.net/iphone/sdkdoc/ and NSFastEnumeration in Swift (convert code to swift). However, when i run app, after choosing image from library, it happen error.
This's my code
import UIKit
import AVFoundation
extension ZBarSymbolSet: SequenceType {
public func generate() -> NSFastGenerator {
return NSFastGenerator(self)
}
}
class FirstViewController: UIViewController, ZBarReaderDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
let reader = ZBarReaderController()
@IBOutlet weak var lblResult: UILabel!
@IBOutlet weak var imgView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
reader.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func scanCode(sender: AnyObject) {
let scanner = reader.scanner
scanner.setSymbology(ZBAR_I25, config: ZBAR_CFG_ENABLE, to: 0)
reader.modalPresentationStyle = .Popover
presentViewController(reader, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
var results: NSFastEnumeration = info["ZBarReaderControllerResults"] as NSFastEnumeration
var symbolFound : ZBarSymbol?
// =============== Error here ==================
for symbol in results as ZBarSymbolSet {
symbolFound = symbol as? ZBarSymbol
break
}
var resultString = NSString(string: symbolFound!.data)
println(resultString)
}
}
here is error image
I will very grateful if someone let me know why it happen error and how to fix it or there's any way to scan code with an image using AVFoundation or there a other library (with detail document and sample) to do this (please give detail instructions because i have just learned swift and ios for 3 weeks).
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…