I also have this problem. My workaround was to add a timestamp or order variable to my TestModel2 equivalent, and then to add a computed property to my TestModel equivalent to return the sorted list when I need it.
@Model
class TestModel {
var name: String?
var unsortedArray: [TestModel2]
var sortedArray: [TestModel2] {
return array.sorted(by: {$0.order < $1.order})
}
init(name: String = "") {
self.name = name
array = []
}
}
@Model
class TestModel2 {
var name: String?
var order: Int
init(name: String = "",order: Int = 0) {
self.name = name
self.order = order
}
}