The error message isn't very clear, but I think what it's trying to convey is that the type you're using isn't compatible with SwiftData (at least not yet). The reason that others have said to use a computed property instead is because you can save the data you actually need to recreate the type that doesn't work.
You're already halfway doing that. I think if you were to remove the @Transient and move the clLocation assignment from your initializer into a computed property, it would work.
struct SomeStruct : Codable {
var latitude: Double
var longitude: Double
// doesn't need to be @Transient if it's computed
var clLocation: CLLocationCoordinate2D {
CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
}
init(latitude: Double, longitude: Double) {
self.latitude = latitude
self.longitude = longitude
}
You did mention that
I'm trying to cache instances of CLLocationCoordinate2D, rather than creating new ones every time a View renders, so those work arounds don't work around.
I don't think it's all that expensive to create the CLLocationCoordinate2D as a computed property when you already have the latitude and longitude handy, but I could be mistaken.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: