UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

what is the best way to declare array of object to fill out table list? data will come from Api if we use Optional array is it the best way and second after that can we check this optional into number of section of table view i need best practice.?

Forums > 100 Days of Swift

var displayUsers : [User]?


if let users = viewModel.users{ self.displayUsers = users DispatchQueue.main.async() { self.tableView.reloadData() self.stopAnimating() } }

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if displayUsers?.count == 0 || displayUsers == nil{ self.tableView.setEmptyMessage("You currently don't have any users, but you can create up to 10.") return 0 } else { return displayUsers?.count ?? 0 } }


TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.