Да, словари не упорядочены по определению, но вы можете создать отсортированный массив ключей словаря
let dict: [Date: [String]] = [:]
let sortedKeys = dict.keys.sorted { $0 < $1 }
, а затем, например, использовать эти отсортированные ключи в источнике данных tableView как раздел
extension NotesViewController: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return sortedKeys.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dict[sortedKeys[section]]?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let value = dict[sortedKeys[indexPath.section]]?[indexPath.row]
else { return UITableViewCell() }
return UITableViewCell()
}
Надеюсь, этот пример поможет вам