Post

Replies

Boosts

Views

Activity

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
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 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