Sobes.tech
Junior — Middle

What information is contained in the DataSource object?

sobes.tech AI

Answer from AI

In iOS, the DataSource object typically contains the information needed to supply data to user interface elements such as UITableView or UICollectionView. It is responsible for:

  • The number of sections and items in each section.
  • Configuring and providing cells for display.
  • Managing the data displayed in a list or collection.

Example of a simple DataSource for UITableView:

class MyDataSource: NSObject, UITableViewDataSource {
    let items = ["Apple", "Banana", "Cherry"]

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        cell.textLabel?.text = items[indexPath.row]
        return cell
    }
}
What information is contained in the DataSource… - sobes.tech