Reputation: 201
What would be the NSPredicate
format equivalent to the following SQL query?
SELECT * FROM tableName ORDER BY date DESC LIMIT 1
I am trying this
let predicate = NSPredicate(format: "ORDER BY date LIMIT 1")
but the error is "Unable to parse the format string"
Upvotes: 3
Views: 2673
Reputation:
A predicate is used for filtering. No filtering here, no predicate needed.
You want to sort your fetched results, which is handled by NSFetchRequest
.
To order your results by date, descending
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)]
To limit your results
fetchRequest.fetchLimit = 1
Upvotes: 9