Post

Replies

Boosts

Views

Activity

Reply to [SwiftData] How to get the first 7 elements by using @Query?
If you create the query property using a FetchDescriptor then you can set a limit for the number of rows being fetched. The drawback of this solution is that it's not a one liner so you need to do it in the init @Query private var records:[Record] init() { var fetchDescriptor = FetchDescriptor<Record>(sortBy: [SortDescriptor(\Record.date, order: .reverse)]) fetchDescriptor.fetchLimit = 7 _categories = Query(fetchDescriptor) } If you for some reason don't want to do it in the init you could declare the fetch descriptor as a static variable and then pass it to the @Query declaration
Nov ’24
Reply to How to evolve from an attribute named throws?
If I understand you correctly the issue is that you can't use the word throws in your code as an attribute name but maybe you can work around that by using backticks around it. I know this works fine for variables and properties and in custom types so hopefully it works within a Core Data/SwiftData context as well. So something like this should work, var `throws`: String
Oct ’24
Reply to Sorting with Complex & Arbitrary Nested Models
You have a complex and dynamic design which will make the whole solution more complex. When you write "...sort the inspections based on the values only in fields with specific labels" it not only is an example of the complexity but it is quite frankly hard to understand how/if it should work. An inspection can have many groups and a group can have many rows so even if you are only sorting on one label with a specific field it will be a complex task to sort the rows and groups for a single inspection not to mention comparing inspections. Since I have no idea what an inspection is in this context and neither what your fields will be filled with it's hard to give any kind of advice but for starters, do you really, really need to sort the inspectors in this manner?
Sep ’24