A
A
Alexander2018-02-06 20:23:31
Swift
Alexander, 2018-02-06 20:23:31

How to sort by date?

There is a list of customers, they have the name and date of orders, you need to output the table view cell by date .. that is, you need to sort when outputting to the table view sorting by the date value (zakazDate) in core data

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Cherny, 2018-02-11
@sasha1802

func getData() {
    let context = appDelegate.persistentContainer.viewContext  

    let fetchRequest = NSFetchRequest<Expenses>(entityName: "Expenses")
    let sort = NSSortDescriptor(key: #keyPath(Expenses.date), ascending: true)
    fetchRequest.sortDescriptors = [sort]
    do {
       expenses = try context.fetch(fetchRequest)
    } catch {
        print("Cannot fetch Expenses")
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question