If you mark the properties in Category as optional then it works fine with no crashes. But then you don't get uniqueness and you're able to insert duplicates into the context.
Post
Replies
Boosts
Views
Activity
I've also come across this issue too
This is still an issue for me in Xcode 15 RC.
Below is an example of the transformer I'm using for saving a UIColor
final class ColorValueTransformer: NSSecureUnarchiveFromDataTransformer {
static let name = NSValueTransformerName(rawValue: String(describing: ColorValueTransformer.self))
override static var allowedTopLevelClasses: [AnyClass] {
return [UIColor.self]
}
public static func register() {
let transformer = ColorValueTransformer()
ValueTransformer.setValueTransformer(transformer, forName: name)
}
}
Here is the entire migrations log attached
Migration Debugging Logs
So i've managed to nail down that the migration is crashing from V3 because I've added a transformable property...It's like it can't find the store after you add a transformable property and crashes. If I make the transformable property @Transient it will clear all of my data and won't crash but it does clear the entire storage like it's a brand new migration.
I've managed to figure it out after like 4 hours... If you're working with migrations and adding in transformable properties make sure they are optional by default...I'm not too sure if this is by design. But after making my transformable properties optional my migrations started to work again.
I am seeing the same behavior too...It doesn't seem to work with enums at all When I compare the enums I get the following in the console
Query encountered an error: SwiftData.SwiftDataError(_error: SwiftData.SwiftDataError._Error.unsupportedPredicate)
When i try to compare the enums using their raw value i get the following crash reffering to a file within the framework
SwiftData/DataUtilities.swift:1140: Fatal error: Unexpected type for Expansion: Optional<UIColor>
The UIColor is reffering to a color that i have as a transformable property
It would be great if this was resolved before the GM release
I am getting a similar crash
SwiftData/DataUtilities.swift:1140: Fatal error: Unexpected type for Expansion: Optional<UIColor>
But this is for a transformable property in my model that is a UIColor, it's happening for me in Xcode 15 RC
So they do work when it comes to CRUD opertations. The issues that i’ve found is when you want to filter or sort i’m getting crashes. Also because my model
uses transformable this is also causing a issues to. it’s almost as if the Query macro can’t handle this type.
i’m going to try and see if it crashes using a FetchDescriptor. If it doesnt then that points me in the direction that Query doesn’t play nicely with custom types…
Ok a bit more info, so it seems that it's more related to the fact that SwiftData doesn't like filtering or sorting on optional values... Below is an example of me filtering based on a non optional string and the fetch request works
let fetch = FetchDescriptor<Item>(predicate: #Predicate { $0.title == "G" })
let results = try? modelContext.fetch(fetch)
print("Found \(results?.count) items") <--- This returns results that match the query
When trying to filter and sort on optional properties like an enum or my property category this is where the issue arises... It seems to crash when trying to access the rawValue and also you get no results when you try to filter based on the case. Below is an example of be executing a query on an optional enum.
let high: Priority = Priority.high
let fetch = FetchDescriptor<Item>(predicate: #Predicate { $0.priority == high })
let results = try? modelContext.fetch(fetch)
print("Found \(results?.count) items") <--- Returns nothing & accessing the raw value crashes...
I hope someone on the Apple team sees this since it seems SwiftData and optionals just don't play nicely...
This is on Xcode 15 RC
Feedback filed FB13202320
Is the ModelActor working for you? I've noticed that no matter what it's always on the main thread. Other developers are seeing this too in Xcode 15 b8 and above.
This still is an issue in Xcode Version 15.1 beta (15C5028h)
This seems to be an issue on simulators in Xcode 15+. The app settings location permissions appear on a real device, but not on any of the simulators. I did find a hack to make it appear and this was by requesting ATT permission this does show both the location & ATT permission.
I’ve filled a feedback myself FB13330752
Below is my post with more info describing the issue.
https://developer.apple.com/forums/thread/740598
Filled a feedback here FB13330752