【发布时间】:2014-11-05 10:51:27
【问题描述】:
我正在尝试将 Objective-C 项目转换为 swift,但我无法找到如何将 NSFastEnumeration 用于符合 NSFastEnumeration 的类的对象。
这是 ObjC 中的代码:
// get the decode results
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// just grab the first barcode
break;
到目前为止,我试图找到如何做到这一点,但这似乎不起作用,这里是 swift 代码:
var results: ZBarSymbolSet = infoDictionary?.objectForKey(ZBarReaderControllerResults) as ZBarSymbolSet
var symbol : ZBarSymbol? = nil;
for symbol in results
{ //just grab first barcode
break;
}
错误来自条件 - “ZBarSymbolSet”没有名为“Generator”的成员
我做错了什么?
这是屏幕截图
【问题讨论】:
-
我也想听听一个真正的解决方案(目前唯一的答案只是说明它为什么不起作用。)
NSFastEnumeration是一个在NSFoundation中广泛使用的协议(NSSet、NSHashTable、NSMapTable、NSPointerArray等)并且扩展所有这些类只是为了符合SequenceType感觉是多余的,而这些类已经支持相同的for-in构造在 Objective-C 中。
标签: ios objective-c swift