ネイティブスウィフト方法がある(contentsOfFileパス)
:
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/ –