Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift Non-void function should return a value in a guard let

Tags:

ios

swift

    guard let cell = tableView
        .dequeueReusableCell(withIdentifier: cellIdentifier) as? FolderAndFileCell else {
        print("some")
        return
    }

It says that

Non-void function should return a value

What should I return here?

like image 468
Serj Semenov Avatar asked Sep 19 '25 18:09

Serj Semenov


1 Answers

Inside cellForRowAt you have to

guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as? FolderAndFileCell else {
    print("some")
    return UITableViewCell()
}

This signature

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

should has a non void return value


The well-know approach is

 let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as! FolderAndFileCell
like image 160
Sh_Khan Avatar answered Sep 22 '25 09:09

Sh_Khan