Swift: Cannot subscript a value of type 'Array' -
i have started learning swift ios development. encountering problem not able solve. can please tell doing wrong? image below contains screenshot of error.
class viewcontroller: uiviewcontroller { @iboutlet weak var tableview: uitableview! @iboutlet weak var daypicker: uipickerview! @iboutlet weak var addbutton: uibutton! @iboutlet weak var textfield: uitextfield! let days = ["sunday","monday","tuesday","thursday","friday","saturday"] // creates array of 7 empty arrays var tabledata:array = [[string]] (count: 7,repeatedvalue:[]) override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } @ibaction func addobjecttotable(sender: anyobject) { if(textfield.text != "") { print (days[daypicker.selectedrowincomponent(0)]) print (textfield.text!) tabledata[daypicker.selectedrowincomponent(0)].append(textfield.text!); // error: cannot subscript value of type 'array' textfield.text = "" tableview.reloaddata() } } }
thanks!
i remembered ran problem few times when went old projects bit outdated. me fix change, in example,
var tabledata:array = [[string]]
to
var tabledata = [[string]]
Comments
Post a Comment