TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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]?

      fetchUsers()

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 } }

3      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.