Bla Bla Bla Bla - 2 months ago 25
Swift Question

Swift 3 Error: "Use of unresolved identifier 'cell'"

I have a problem in Xcode8/Swift3. I have a UITableView in a UIViewcontroller and I get the Error:

Use of unresolved identifier 'cell'
.

The code of the
ViewContoller.swift
is:

import UIKit

class WOWViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

@IBOutlet weak var tableView: UITableView!

var Hundenamen = ["Pete", "Washi", "WuffWuff", "Hundi", "TrallaBalla"]
var Hunderassen = ["Dackel", "Pudel", "Unbekannt", "Labrador", "Unbekannt"]

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! THISTableViewCell
cell.Hunderasse.text = Hunderassen[indexPath.row]
cell.Hundename.text = Hundenamen[indexPath.row]
return cell
}
}


And at these lines:

cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! THISTableViewCell
cell.Hunderasse.text = Hunderassen[indexPath.row]
cell.Hundename.text = Hundenamen[indexPath.row]
return cell


In Swift2 it worked, but the code of the last function has changed.

Answer

Use the let keyword:

    let cell = self.tableView.dequeueReusableCell(withIdentifier: 
Comments