美文网首页
NSFastEnumeration in Swift

NSFastEnumeration in Swift

作者: fishycx | 来源:发表于2019-10-09 16:39 被阅读0次

项目中使用了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)

}

解决

相关文章

  • NSFastEnumeration in Swift

    项目中使用了ZBar , 因为使用的swift,遇到如下问题: 在识别二维码内容时调用了如下方法: guard l...

  • NSFastEnumeration

    今天看了个alibaba的开源库coobjc,看到了代码中使用了实现NSFastEnumeration协议的类进行...

  • NSFastEnumeration

    NSFastEnumeration 前言 最近在实现一个自定义的容器类,在实现过程中,突然想到,如果别人在遍历这个...

  • 实现快速枚举 NSFastEnumeration

    基础知识 快速枚举有两个优点。一是,实现快速枚举后,你可以直接使用for/in语法遍历你的对象。二是,如果将快速枚...

  • NSFastEnumeration使用原理分析

    前言:集合类在每门编程语言中都有着非常重要的地位,每一门语言对于集合类的实现和提供的API也大同小异。相比于Jav...

  • 快速枚举协议:NSFastEnumeration

    问题 下面的代码输出是什么?会不会Crash?如果Crash解释一下原因。 答案 控制台的输出给出了所有的答案: ...

  • 中文版链接

    中文版链接swift-4.0swift-3.1swift-3.0swift-2.2swift-2.1swift-2.0

  • Swift -- 中文版两大官方文档汇总(http://www.

    欢迎使用Swift (一)关于Swift--About Swift (二)Swift 初见--A Swift To...

  • swift String to Size

    Swift 4 Swift 3 Swift 2.3

  • swift第一讲

    swift系列课程 编译流程 Swift code --> Swift AST -->Raw Swift IL ...

网友评论

      本文标题:NSFastEnumeration in Swift

      本文链接:https://www.haomeiwen.com/subject/uopgpctx.html