0
我有一個混合(Swift/Objective C)iOS項目。下面是我的iOS應用雨燕代碼片段:訪問Swift的Objective C中的可選類型
let envPlist = NSBundle.mainBundle().pathForResource("environment", ofType: "plist")
let envDict = NSDictionary(contentsOfFile: envPlist!)
class BuildEnv: NSObject {
internal class func envKey() -> String? {
return envDict["envKey"]?.string
}
}
當我的目標C日誌打印envKey:
NSLog(@"BUILDENV ENV = %@", [BuildEnv envKey]);
我:
BUILDENV ENV = (null)
但是,如果我改變了斯威夫特功能:
internal class func envKey() -> String {
return envDict["envKey"] as String!
}
然後我是能夠打印Objective C中的值。有誰知道如何處理這個優雅?
你似乎在呼喚您'NSDictionary'返回,這裏的價值'string'屬性:''envDict [「envKey」]?。string',但不能晚於:'envDict [「envKey」] as String!'。這是爲什麼? – 2014-10-04 05:23:30