天然雨燕的方法是使用PropertyListSerialization
if let url = Bundle.main.url(forResource:"Config", withExtension: "plist") {
do {
let data = try Data(contentsOf:url)
let swiftDictionary = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as! [String:Any]
// do something with the dictionary
} catch {
print(error)
}
}
您還可以使用NSDictionary(contentsOf:
用一個類型轉換:
if let url = Bundle.main.url(forResource:"Config", withExtension: "plist"),
let myDict = NSDictionary(contentsOf: url) as? [String:Any] {
print(myDict)
}
但是你明確地寫道:不使用的NSDictionary(contentsOf ...
基本上不無斯威夫特鑄造用NSDictionary
,你扔掉的重要類型的信息。
你的問題是什麼?你想達到什麼目的? – Adeel
需要swift3轉換爲以上代碼 –
請參閱我的網站https://ioswisdom.000webhostapp.com/ –