1

I'm doing a dictionary application. firebase also has a dictionary title and description. I pull this data into x code. I will show the title in the table view cell. but I could not sort it in alphabetical order, for example; to apple B book I want to sort it.

I will only list fizik.baslik. swift 4, I work in xcode 10.3

 class FizikSozluk{
    var fizik_id : String?
    var baslik :String?
    var aciklama:String?
    var animasyonAdi:String?





@IBOutlet weak var tableview: UITableView!

@IBOutlet weak var seachbar: UISearchBar!
var fizikListe = [FizikSozluk]()


var ref : DatabaseReference!

extension ViewController2 : UITableViewDelegate, UITableViewDataSource{

func numberOfSections(in tableView: UITableView) -> Int {

    return 1

}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    fizikListe.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let fizik = let fizik = self.fizikListe.sorted(by: { $0.baslik ?? "" < $1.baslik ?? ""})[indexPath.row]

    let cell = tableView.dequeueReusableCell(withIdentifier: "sozluk", for: indexPath) as? TableViewCell


    cell?.baslik.text = fizik.baslik




    return cell!

}

Sort the information alphabetically with the above code. however, with the staging function, the information I send to the other view controller is mixed. I also want to sort the information under letters.

A apple

B book

0 Answers0