I created Dictionary like below,
let bookList = [
["title" : "Harry Potter",
"author" : "Joan K. Rowling"
"image" : image // UIImage is added.
],
["title" : "Twilight",
"author" : " Stephenie Meyer",
"image" : image
],
["title" : "The Lord of the Rings",
"author" : "J. R. R. Tolkien",
"image" : image]
and I'd like to make a tableView using this book list.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "listCell") as? ListCell else { return UITableViewCell() }
let book = bookList[indexPath.row]
cell.configureCell(title: book.???, author: ???, bookImage: ???)
return cell
}
How should I use value and key of Dictionary to configure Cell?
It's highly recommended to use a custom struct rather than a dictionary
The huge benefit is you have distinct non-optional types without any type cast
Further I'd declare
configureCell
and pass
Then you can assign the members of the struct directly to the labels in
configureCell