ios - 从 Swift 3.0 到 Swift 4.2 的转换错误 "Cannot assign value of type ' [String ]' to type ' [AVMetadataObject.ObjectType] ?'"

标签 ios swift swift3 swift4.2 xcode10.3

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

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

Cannot assign value of type '[String]' to type '[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.

最佳答案

迁移器会尽力提供帮助,但有时这种帮助会产生误导。

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

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

关于ios - 从 Swift 3.0 到 Swift 4.2 的转换错误 "Cannot assign value of type ' [String ]' to type ' [AVMetadataObject.ObjectType] ?'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57963713/

相关文章:

ios - Swift 图像按钮上的淡入淡出(过渡效果)

compare - 如何比较来自 UIImagePNGRepresentation 的 2 个数据?

ios - 从 bundle 的 Assets 文件夹中加载图像

iphone - iOS,AudioUnits 记录到本地 URL

javascript - 如何在此示例 Codepen 上使用 Ipad Safari? (看起来像一场噩梦)

ios - 关闭多个推送 View Controller

ios - Swift:错误:链接器命令失败,退出代码为 1

swift - 有没有办法让一个函数在不重新指定所有参数的情况下调用自己?

ios - 我的警报 Controller 操作究竟如何将文本 append 到标签?

ios - 适用于Xcode 5的iOS 8模拟器