uitableview - Swift - UITableViewCell? is not convertible to UITableViewCell -


i'm new swift development , following many online tutorials. majority of these tutorials referring older versions on xcode , code resulting in errors. can explain why code below produces 'uitableviewcell?' not convertible uitableviewcella , how go fixing problem.

i using xcode 7.

override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {      let cell = tableview.dequeuereusablecellwithidentifier("customcell") uitableviewcell          cell.textlabel?.text = array[indexpath.item]         return cell } 

there 2 methods

1)

func dequeuereusablecellwithidentifier(_ identifier: string) -> uitableviewcell? 

which returns optional have unwrap optional

let cell = tableview.dequeuereusablecellwithidentifier("custom cell")! 

the other method preferable

2)

func dequeuereusablecellwithidentifier(_ identifier: string,                       forindexpath indexpath: nsindexpath) -> uitableviewcell 

because returns non-optional

let cell = tableview.dequeuereusablecellwithidentifier("custom cell", forindexpath:indexpath) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -