When using SwiftData + PassColor, I encounter a consistent crash:
Could not cast value of type '__NSCFNumber' to 'NSString'
This happens when saving a model with an optional PassColor? and then fetching it back.
The crash seems to occur here.
Below is a code sample you can copy/paste that will allow you to easily reproduce the same issue:
import PassCore
import SwiftUI
import SwiftData
@Model
final class WalletPass {
var name: String
var labelColor: PassColor?
init(name: String, labelColor: PassColor?) {
self.name = name
self.labelColor = labelColor
}
}
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query private var passes: [WalletPass]
var body: some View {
List {
Button("Insert Pass") {
let pass = WalletPass(
name: "Some Pass",
labelColor: .init(r: 255, g: 0, b: 0)
)
modelContext.insert(pass)
try? modelContext.save()
}
ForEach(passes) { pass in
Text(pass.name)
}
}
}
}
@main
struct TestingPassColorCrashApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(for: [WalletPass.self])
}
}
When using SwiftData + PassColor, I encounter a consistent crash:
This happens when saving a model with an optional
PassColor?and then fetching it back.The crash seems to occur here.
Below is a code sample you can copy/paste that will allow you to easily reproduce the same issue: