Today, I learned how to sort and filter core data. Much simpler than I would have thought!
You can’t beat the way Chris explains these concepts… I would love to find a similar course-set for Kotlin or how to develop Android apps.
This piece of code sorts the people by age as well as filters only for users named Joe:
@FetchRequest(sortDescriptors: [ NSSortDescriptor(key: "name", ascending: true), // Sort by name first NSSortDescriptor(key: "age", ascending: true) // Then sort by age ], predicate: NSPredicate(format: "name contains 'Joe'")) var people: FetchedResults<Person>
See Apple’s docs for more details on how to use
predicates to filter the data: Apple Developer Documentation