此代码适用于Swift 3,但因Swift 4错误而失败:
'Sequence'需要类型'ZBarSymbolSet.Element'(又名'ZBarSymbol')和'Any'是等价的
extension ZBarSymbolSet: Sequence
{
public typealias Element = ZBarSymbol
public typealias Iterator = NSFastEnumerationIterator
public func makeIterator() -> NSFastEnumerationIterator
{
return NSFastEnumerationIterator(self)
}
}
...
if (self.ZBarReader == nil) {
self.ZBarReader = ZBarReaderViewController()
}
self.ZBarReader?.readerDelegate = self
self.ZBarReader?.scanner.setSymbology(ZBAR_UPCA, config: ZBAR_CFG_ENABLE, to: 1)
self.ZBarReader?.readerView.zoom = 1.0
self.ZBarReader?.isModalInPopover = false
self.ZBarReader?.showsZBarControls = false
navigationController?.pushViewController(self.ZBarReader!, animated:true)
...
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
guard let symbols = info[ZBarReaderControllerResults] as? ZBarSymbolSet else { return }
for symbol in symbols
{
if let symbol = symbol as? ZBarSymbol, let data = symbol.data
{
print(data)
}
}
}
我在这里做错了什么?