I don't know how to approach this issue, so I'm looking for some suggestions:
I have an airports list database with over 75K airports on it, and it is very very slow to open it when I use on my view@Query() var airports: [Airport]
So I understand I need to load a shorted list of this array, for each alphabet letter I want to pick 10 airports and add it to a 'shortairports' array in order to display it faster.
my attempt:
On the model I have tried to add a static var that should return a FetchDescriptor shorted to be used in my view as @Query(short) var airports: [Airport]
but I'm stuck... see below code:
@Model
class Airport {
@Attribute(.unique) var id: UUID
var lastPicked : Date
var icao : String
init(id: UUID, lastPicked: Date, icao: String) {
self.id = id
self.lastPicked = lastPicked
self.icao = icao
}
static var short: FetchDescriptor<Airport> {
let alphabet = ["0","1","2","3","4","5", "6", "7", "8", "9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
let sort = [SortDescriptor(\Airport.icao, order: .forward)]
var shortAirports = FetchDescriptor<Airport>()
alphabet.forEach { letter in
let predicate = #Predicate<Airport> { input in
input.icao.prefix(1) == letter // error here //
//The prefix(_:) function is not supported
}
var apts = FetchDescriptor(predicate: predicate, sortBy: sort)
apts.fetchLimit = 10
// now i have 10 airports i wanted to add in an array of [Airports]
// shortAirports.append ?? /// <--->
}
return shortAirports
}
}