我有一組字符串,其中包含一些數據。 但是,當我顯示的數據從設置到tableView,在cellForRowAtIndexPath方法,它給了我上述的錯誤。 這裏是我的代碼:不能使用類型'Int'的索引對'Set <String>'類型的值進行下標
var tradeSet: Set<String> = ["TKAI", "YNDX", "PSTG"]
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MyTrade", forIndexPath: indexPath) as! MyTradeTableViewCell
let objects = tradeSet[indexPath.row]
cell.tradeName.text = objects
return cell
}
任何幫助將是偉大的。謝謝!
「集合」是一種無序的集合類型,不能通過索引對其進行下標。 – vadian
你必須將set轉換爲數組。 –
@vadian Well *技術上*它可以通過索引下標,只是一個'SetIndex',而不是'Int';) – Hamish