My preview crashes whenever I compare my model's value to a constant's stored value.
I use struct constants with a stored value as alternatives to enums, (IIRC ever since the beginning) enums never worked at all with .rawValue or computed properties.
This crashes when it runs on Xcode 16.3 beta and iOS 18.4 in previews. It doesn't appear to crash in simulator.
@Model class Media {
@Attribute(.unique) var id: UUID = UUID()
@Attribute var type: MediaType
init(type: MediaType) {
self.type = type
}
static var predicate: (Predicate<Media>) {
let image = MediaType.image.value
let predicate = #Predicate<Media> { media in
media.type.value == image
}
return predicate
}
}
struct MediaType: Codable, Equatable, Hashable {
static let image: MediaType = .init(value: 0)
static let video: MediaType = .init(value: 1)
static let audio: MediaType = .init(value: 2)
var value: Int
}
My application crashes with "Application crashed due to fatalError in Schema.swift at line 320."
KeyPath \Media.<computed 0x000000034082a33c (MediaType)>.value points to a field (<computed 0x000000034082a33c (MediaType)>) that is unknown to Media and cannot be used.
This appears to also occur if I am using a generic/any func and use protocols to access a property which is a simple String, such as id or name, despite it being a stored SwiftData attribute.
I filed a bug report, but looking to hear workarounds.