Type 'TodoList' does not conform to protocol 'UITableViewDataSource'

#1

I have a question with regard to error description about Type ‘TodoList’ does not conform to protocol ‘UITableViewDataSource’.

Could you help me about the error message

import UIKit

class TodoList: NSObject
{
private var items: [String] = []

func addItem(item: String)
{
    items.append(item)
}

}

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

#2

It seems that at least TodoList lacks of ‘tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell’ protocol method

#3

Thank you sir, now I have another trouble with the Error: Use of unresolved identifier ‘items’

How can I correct this error,

import UIKit

class TodoList: NSObject
{
private var items: [String] = []

func addItem(item: String)
{
    items.append(item)
}

}

extension TodoList: UITableViewDataSource
{

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")

    let item = items[indexPath.row]

    cell.textLabel!.text = item

    return cell!
}

}

#4

this is due to accessibility rules on extension.

use this:

    fileprivate var items: [String] = []

instead of

    private var items: [String] = []