Can't store Codable Size3D in SwiftData

I got a @Model class with a property of a codable "Options" struct.

import SwiftData

@Model
final class Project {   
    var options: Options
}

In this struct I have another property called "resolution" of type Size3D.

import Spatial

struct Options: Codable {
    var resolution: Size3D
}

I can initially launch the app and save a project with a custom resolution. Tho when I try to re-launch the app it crashes:

Could not cast value of type 'Swift.Optional<Any>' (0x1fa251d80) to '__C.SPSize3D' (0x1047dcbc0).

Size3D is codable, tho it does not seem to currently be supported by SwiftData.

My current solution is to have a middle type that I store in my options struct like this:

struct Options: Codable {

    private struct CodableResolution: Codable {
        
        let width: Double
        let height: Double
        let depth: Double
        
        var size: Size3D {
            Size3D(width: width, height: height, depth: depth)
        }

        init(_ size: Size3D) {
            self.width = size.width
            self.height = size.height
            self.depth = size.depth
        }
    }

    private var codableResolution: CodableResolution

    var resolution: Size3D {
        get {
            codableResolution.size
        }
        set {
            codableResolution = CodableResolution(newValue)
        }
    }
}

Note that I'm testing this on the visionOS simulator with Xcode 15.2 on macOS 14.0

Feedback: FB13543953

Can't store Codable Size3D in SwiftData
 
 
Q