に型「Swift._SwiftDeferredNSDictionary
// Connect to plist and get the data
if let plist = PlistHandler(name: "MovieData") {
getPlist = plist.getMutablePlistDict()!
// Load the movie items into the table view data source
for i in 0..<getPlist.count {
movieItems = (getPlist.object(forKey: "Item\(i)") as! NSMutableDictionary) as! [String: String] as! NSMutableDictionary
let newName = movieItems.object(forKey: "Name")
let newRemark = movieItems.object(forKey: "Remark")
if newName as? String != "" {
movies.append(Movie(name: newName as? String, remark: newRemark as? String)
)}
}
} else {
print("Unable to get Plist")
}
::私はplistの内容をロードしている次のような方法があります
// Get the values from plist -> MutableDirectory
func getMutablePlistDict() -> NSMutableDictionary? {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: destPath!) {
guard let dict = NSMutableDictionary(contentsOfFile: destPath!) else { return .none }
return dict
} else {
return .none
}
}
私は、アプリケーションを実行すると上記のエラーが表示されます(質問タイトルを参照)。しかしこれは新しいものです。 Xcode 8ではこのエラーは発生しませんでした。これの理由は何ですか?それを避けるためにコードを変更する必要がありますか?
あなたはこのように使用することができます
構文 'として! NSMutableDictionary)として! [String:String]として! NSMutableDictionary'は恐ろしいです。エラーメッセージはかなり明確です。 Swift辞書を 'NSMutableDictionary'にキャストすることはできません。 ** Swiftでは 'NSMutable ...'コレクション型を使用しないでください**。辞書を '[String:String]'として宣言してください。 'var'キーワードを使うと、自由に変更可能です。そして、代わりに 'NSMutableDictionary(contentsOfFile'は' PropertyListSerialization'を使用します。 – vadian
ヒントありがとうございます! – Martin