ios - Cannot subscript a value of type 'Set<String>' with an index of type 'Int' -
i having set of strings have data in it. when showing data set tableview, in cellforrowatindexpath method gives me above stated error. here code:
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 }
any great. thank you!
a set not indexable, because order in elements of set listed irrelevant. should storing elements in array or different data structure. quick following (not recommended):
var tradeset: set<string> = ["tkai", "yndx", "pstg"] func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("mytrade", forindexpath: indexpath) as! mytradetableviewcell // not best data structure job tho (index, element) in tradeset.enumerated() { if row == index { cell.tradename.text = element } } return cell }
these kind of scenarios suggest incorrect data structure/algorithm.
Comments
Post a Comment