NSFastEnumeration in Swift

項目中使用了ZBar , 因爲使用的swift,遇到如下問題:
在識別二維碼內容時調用瞭如下方法:

guard let results = reader.scanImage(image) else {
    return ""
}

在 OC中可以使用如下方法獲取內容值

/  get the decode results
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];

ZBarSymbol *symbol = nil;
for(symbol in results)
    // just grab the first barcode
    break;

swift 怎麼獲取呢。

stackoverflow 上給了相關答案,但好像不好使。親測會crash的。

其實可以換中遍歷方式:

guard let results = reader.scanImage(image) else {
    return ""
}
var symbolFound : ZBarSymbol?
var iterator = NSFastEnumerationIterator(results)
while let symbol = iterator.next() {
    symbolFound = symbol as? ZBarSymbol
    BBLog(message: symbolFound)
}

解決

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章