【发布时间】:2014-09-26 01:06:46
【问题描述】:
我正在从主要NSBundle 的infoDictionary 属性进行字典查找。这可以正常工作:
let infoDict = NSBundle.mainBundle().infoDictionary
var item = infoDict["CFBundleExecutable"]
if let stringValue = item as? String {
...
}
但是,我想把它们串起来。但是,当我这样做时,我收到一个编译器错误:
if let stringValue = NSBundle.mainBundle().infoDictionary["CFBundleExecutable"] as? String {
...
}
错误是:
'String' is not a subtype of '(NSObject, AnyObject)'
我意识到这是那些神秘的 Swift 编译器消息之一,它意味着比它明确声明的更微不足道的东西 - 但我无法确定我上面的两个代码 sn-ps 有何不同 - 为什么一个有效,一个无效.
【问题讨论】: