Here You Go , Try This Out  : - 
struct ExpandableNames {
    var isExpanded : Bool
    var names : [String]
}
struct Contact {
    let names : String
}
in your Class - >
var twoDArray = [
    ExpandableNames(isExpanded : true,names:["Krishna","Rishabh","Aditya","Chandan","Nipun","Navdeesh","Steve"].map
    {
            Contact(names: $0)
    }),
    ExpandableNames(isExpanded : true,names:["Carl","Michal","Tommy","Jennny","Vikram","Swati"].map
    {
            Contact(names: $0)
    }),
    ExpandableNames(isExpanded : true,names:["David","dude","dfff","dcc","daa","dee","dsss"].map
    {
        Contact(names: $0)
    }),
    ExpandableNames(isExpanded : true,names:[Contact(names: "Pattrick", hasFav: false)])
                ]
let cellId = "cellID"
let identifier = "attachmentCellID"
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
{
    return 50
}
func numberOfSections(in tableView: UITableView) -> Int
{
    return twoDArray.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    if !twoDArray[section].isExpanded
    {
        return 0
    }
    return twoDArray[section].names.count
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
{
    let btn = UIButton(type: .system)
    if(section == 0)
    {
        btn.setTitle("Tap To View Classes", for: .normal)
    }
    else if(section == 1)
    {
        btn.setTitle("Tap To View Admins", for: .normal)
    }
    btn.setTitleColor(.black, for: .normal)
    btn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
    btn.addTarget(self, action: #selector(handleExpandClose), for: .touchUpInside)
    btn.backgroundColor = AppColors.greyBorderColor
    btn.tag = section
    return btn
}
@objc func handleExpandClose(button : UIButton)
{
    let section = button.tag
    var indexPaths = [IndexPath]()
    for row in twoDArray[section].names.indices
    {
        let indexPath = IndexPath(row: row, section: section)
        indexPaths.append(indexPath)
    }
    let isExpanded = twoDArray[section].isExpanded
    twoDArray[section].isExpanded = !isExpanded
    button.setTitle(isExpanded ? "Tap To View Classes" : "Classes", for: .normal)
    if isExpanded
    {
        tableView.deleteRows(at: indexPaths, with: .fade)
    }
    else
    {
        tableView.insertRows(at: indexPaths, with: .fade)
    }
}
And Rest in cellForRowAt - 
 let contact = twoDArray[indexPath.section].names[indexPath.row]
    cell.textLabel?.text = contact.names