Search code examples
swift3zbar-sdk

Using zbar sdk and converting to swift 3, will it work?


I'm planning to convert the code to Swift 3 in xCode 8, but I'm hesitant to do so, because of the frameworks I use, especially ZBar SDK (I'm getting it with CocoaPods). Does anyone know, if the conversion can make this (or other) framework unusable?


Solution

  • The only changes should be the protocol part, you may refer to this post.

    How to import Zbar Framework in Swift Project

    extension ZBarSymbolSet: Sequence {
        public func makeIterator() -> NSFastEnumerationIterator {
            return NSFastEnumerationIterator(self)
        }
    }
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        // ADD: get the decode results
        let results: NSFastEnumeration = info[ZBarReaderControllerResults] as! NSFastEnumeration
    
        var symbolFound : ZBarSymbol?
    
        for symbol in results as! ZBarSymbolSet {
            symbolFound = symbol as? ZBarSymbol
            break
        }
        let resultString = symbolFound!.data
        print(resultString)
    }