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

      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 RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.