Hello, I’m used to using SQL queries, but it’s been a few years for that as well.
I have a (forgive my terms, new to swift). Entity with only a few attributes.
One being ‘date’. I’d like to create the output of the order of any day that’s today or in the future, in the order of closest at the top, and furthest at the bottom, with any date that’s older than today, in the same order, after the last future date.
before that join, though, it should sort alphabetically on ‘eventName’ in case there are multiple events on the same day.
Hopefully that makes sense.
I think in SQL I’d do 2 queries using today’s date and a join or union. grab both as one, then pass it to my app.
But in here, I’m new to this. I did get it to sort by date, but it puts past dates at very top.
thanks for any help. I’ll keep messing with it as well.
or maybe get the data then pass it to an array then use the array to build the table?
or make 2 arrays from 2 queries and join them after and use that to build the table?
I’m only working with 3 attributes, and maybe a dozen rows, so efficiency is nice, but nothing will break from the amount of data.
func getAllItems() {
do {
let request = DazeData.fetchRequest() as NSFetchRequest<DazeData>
let sort = NSSortDescriptor(key: "eventDate", ascending: true)
request.sortDescriptors = [sort]
dazeTable = try context.fetch(request)
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
catch {
// error handler go here
}
}