Quantcast
Viewing latest article 4
Browse Latest Browse All 4

Defining 'UITableViewCell' variable in Swift 2.0

I am trying to create UITableViewCell type variable with swift, these are my codes:

 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dwarves.count
    }

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier)! as UITableViewCell
    if (cell == nil) {
        cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: simpleTableIdentifier)
    }

    cell.textLabel?.text = dwarves[indexPath.row]
    return cell
}

In 7th line if (cell == nil), it gives me an error that Value of type 'UITableViewCell' can never be nil, comparison isn't allowed. It can't be replaced by if ( !cell ). How should I fix the codes?


Viewing latest article 4
Browse Latest Browse All 4

Trending Articles