Post

Replies

Boosts

Views

Activity

Reply to SwiftData crash when using a @Query sort descriptor with a relationship
Running into similar issue here. Adding error from console so other devs can find this when searching. SwiftData/Schema.swift:305: Fatal error: KeyPath \Caliber.<computed 0x000000010273b228 (Manufacturer)>.<computed 0x000000010273b230 (String)> points to a field (<computed 0x000000010273b228 (Manufacturer)>) that is unknown to Caliber and cannot be used. From my investigation sort descriptor pointing to a relationship on a model is to blame (doesn't have to be @Query property wrapper, also used in FetchDescriptor crashes). Possible workaround - copy property from relationship to model and sort by it.
1w
Reply to After upgrading to XCode 16 app stopped working
User should be able to filter CaliberData by specifying size range. #Predicate { caliberData in caliberData.sizeHeights.contains { sizeObject in sizeObject.id >= minSizeHeight && sizeObject.id <= maxSizeHeight } } You are right, that Float is actual size value, but had to wrap it into a custom class as a workaround due to some SwiftData limitation regarding using filtering predicates on value (or relationships (or both)). So using the actual value as 'id' to make it conform to needed Identifiable protocol made sense to save some space.
Oct ’24
Reply to After upgrading to XCode 16 app stopped working
As a workaround until better solution is found this works: import Foundation import SwiftData @Model class CaliberData: Identifiable { var id: UUID = UUID() var sizeHeights: [SizeObject] @Transient var sizeHeightsCopy: [SizeObject] // <-here var featuresABCDIds: [Int] init( id: UUID, sizeHeights: [SizeObject], featuresABCDIds: [Int], ) { self.id = id self.sizeHeights = sizeHeights self.featuresABCDIds = featuresABCDIds sizeHeightsCopy = sizeHeights // <-here } extension CaliberData: Equatable { static func == (lhs: CaliberData, rhs: CaliberData) -> Bool { lhs.featuresABCDIds == rhs.featuresABCDIds && lhs.sizeHeightsCopy == rhs.sizeHeightsCopy // <-here } }
Oct ’24
Reply to SwiftData using Predicate on an Array
if you use collections of value types, e.g. [String], SwiftData will save that directly inside a single property too. Right now it’s encoded as binary property list data, which means you can’t use the contents of your array in a predicate. More: https://www.hackingwithswift.com/quick-start/swiftdata/using-structs-and-enums-in-swiftdata-models
May ’24