【问题标题】:Conversion errors from Swift 3.0 to Swift 4.2 "Cannot assign value of type '[String]' to type '[AVMetadataObject.ObjectType]?'"从 Swift 3.0 到 Swift 4.2 的转换错误“无法将类型 '[String]' 的值分配给类型 '[AVMetadataObject.ObjectType]?'”
【发布时间】:2020-01-17 16:42:24
【问题描述】:

我是 Swift/iOS 开发的新手,正在将 Swift 3.0 项目转换为 Swift 4.2 以支持更新的设备。

在此过程中,我收到以下错误:

无法将类型“[String]”的值分配给类型“[AVMetadataObject.ObjectType]?”

以下是引发错误的代码行:

let metadataOutput = AVCaptureMetadataOutput()

metadataOutput.metadataObjectTypes = [convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.upce),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.code39),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.code39Mod43),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.ean13),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.ean8),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.code93),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.code128),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.pdf417),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.aztec),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.interleaved2of5),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.itf14),
                                      convertFromAVMetadataObjectObjectType(AVMetadataObject.ObjectType.dataMatrix)]// Support for AVMetadataObjectTypeQRCode / qr code is removed from the list.

【问题讨论】:

    标签: ios swift swift3 swift4.2 xcode10.3


    【解决方案1】:

    迁移者尽其所能提供帮助,但有时这种帮助具有误导性。

    您可以只使用静态成员填充数组

    metadataOutput.metadataObjectTypes = [.upce, .code39, .code39Mod43, .ean13, .ean8, .code93, .code128, .pdf417, .aztec, .interleaved2of5, .itf14, .dataMatrix]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多