因此,根據以下項目教程expandableCells,使用NSMutableArray的子腳本工作。 (我自己在xcode中打開了項目,並且沒有錯誤)想知道是否有人知道爲什麼在一個項目中創建「ambigious use of subscript」錯誤是因爲在一個項目中相對於另一個項目創建了
當我嘗試在我自己的項目中使用這個工作流程時,我得到了「模糊使用下標」錯誤。這是在上一個問題Ambiguous use of subscript
我的問題是爲什麼項目提供的appcoda在xcode中工作,但類似的代碼不工作時嘗試在新項目中使用類似的工作流程。現在請注意,問題似乎是swift如何處理NSMutableArray,因爲當我將代碼重寫爲swift數組和字典時,除了沒有簡單的方法將plist轉換爲swift數組之外,其他所有工作都可以使用。
我的plist是在相同的格式教程:數組,數組,字典
這是由於在您鏈接到的答覆是解釋我在哪裏看到的錯誤
var cellDescriptors: NSMutableArray!
func loadSections() {
let path: String = NSBundle.mainBundle().pathForResource("NewCells", ofType: "plist")!
cellDescriptors = NSMutableArray(contentsOfFile: path)
getIndicesOfVisibleRows()
tblExpandable.reloadData()
}
func getIndicesOfVisibleRows() {
visibleRowsPerSection.removeAll()
for currentSectionCells in cellDescriptors {
var visibleRows = [Int]()
for row in 0...((currentSectionCells).count - 1) {
**ERROR HERE==>** if currentSectionCells[row]["isVisible"] as! Bool == true {
visibleRows.append(row)
}
}
visibleRowsPerSection.append(visibleRows)
print("visibleRows \(self.visibleRowsPerSection)")
}
}
嘗試加載它並將其轉換爲[AnyObject]。 var cellDescriptors:[AnyObject] = [] cellDescriptors = NSArray(contentsOfURL:url)as? [AnyObject] ?? []' –
這取決於很多事情,如果爲'AnyObject'應用下標引起「不明確使用下標」或不。列出項目中的所有導入,並查看其中哪些影響。 – OOPer
@leo,那沒用。這引發了令人討厭的分段錯誤錯誤。在OOPer,我唯一的進口是UIKit。感謝大家的迴應。 – Chris