我有被設置爲以下所示的的plist:在具有多維陣列的字典的plist夫特環
我想在每個的該加載到一個變量,然後循環項目。這是我到目前爲止的代碼,但無濟於事我看到錯誤「Type'AnyObject'不符合協議'SequenceType'」。
func startTournament(sender: UIBarButtonItem) {
var map: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("knockout_single_8", ofType: "plist") {
map = NSDictionary(contentsOfFile: path)
}
var matches = NSMutableDictionary()
let rounds = map?["rounds"] as NSArray
for match in rounds[0] { // Error from this line
let mid = match["mid"]
let match = ["names": ["testA", "testB"]]
matches[mid] = match
}
}
您可以發佈引發'Type'AnyObject'的行不符合協議'SequenceType'。但是,我認爲輪是一個可選類型的變量,嘗試'讓rounds = map![「rounds」]作爲NSArray' – gabuh
@ gabuh謝謝,我已經添加了一段代碼註釋,以顯示哪條線吐出了錯誤。我嘗試了你的建議,但同樣的錯誤在那裏。 – Fenda
在for之前加上'var rounds0:Array = rounds [0] as Array',並迭代rounds0,不輪迴[0] – gabuh