UITableViewDataSource with different sections and SearchController
The numberOfRowsInSection: function looks good to me, changing this function to something better will depend on the possible logic you can apply in combination with the section parameter and your data. For example, if you have an array of dictionaries like this:

let data = [ 1: ["hola", "hey"], 2: ["adiós"] ]


The implementation of the method could be reduced to:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
    if self.searchController.isActive {
        let array = searchData[section]
        return array.count
    }
    let array = data[section]
    return array.count
}


That indeed is valid for five sections and for one millions sections.

For the cellForRowAt indexPath: function, I would put first the check for the searching status:

if self.searchController.isActive {
    // handle sections for searching
} else {
    // handle sections normaly
}


Doing it like this will allows you to, for example, group functionality shared across multiple sections. An implementation taking the example I put could be like:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
    let text = ""
    if self.searchController.isActive {
        let array = searchData[indexPath.section]
        text = array[indexPath.row]
    } else {
        let array = data[indexPath.section]
        text = array[indexPath.row]
    }

    configureCell(with: text, at: indexPath)
}


I did this because I prefer to not overload so much the implementation of the delegates. In configureCell:at: you must implement the logic needed for the creation of the cells based in sections and the data you received.

As I wrote before, the implementation of those methods will depends on the structure of your data, it could reduce or increase the amount of code you need to show the data in the intended way.