Sectioned fetching: beyond String keyPaths?

Hello, world! First and foremost, thank you for all the enhancements made to SwiftData and kudos to the team!

In Thomas’ video demonstrating “What’s new in SwiftData”, I notice the keyPath (trip.destination) used to create sections in the list is a String. I can’t help but wonder if a keyPath of another data type could be used (like trip.startDate), were one to want to create sections based on whether a trip is past or upcoming for example?

Thank you in advance for your much appreciated input!

Zoé

Answered by Frameworks Engineer in 891803022

Hi Zoé,

Both the ResultsObserver and the sectioned @Query only support string key paths for sectioning. If you have needs for different types can you file a Feedback Assistant.

However if you need to only want to do "past and upcoming" with two different @Query with a predicate to filter for upcoming and past trips - similar to Matthew's Talk.

Hi Zoé,

Both the ResultsObserver and the sectioned @Query only support string key paths for sectioning. If you have needs for different types can you file a Feedback Assistant.

However if you need to only want to do "past and upcoming" with two different @Query with a predicate to filter for upcoming and past trips - similar to Matthew's Talk.

Sectioned fetching: beyond String keyPaths?
 
 
Q