The following code gives me an "error: <EXPR>:1:1: error: use of unresolved identifier 'sampleArray'." Shouldn't I be able to declare an array in a class, add to it in one method and then access it's data in another method in the same class? It keeps giving me this error and it goes against everything I've known about object oriented programming. I must be missing something obvious. Please help me find a solution to this.
class SampleController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var sampleArray= Array<String>()
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
cell.title.text = sampleArray[ndexPath.row] as String //error: <EXPR>:1:1: error: use of unresolved identifier 'sampleArray'
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
sampleArray.append("Data 1")
sampleArray.append("Data 2")
}
}