Issue storing SIMD3<Float> (and other simd’s) in a SwiftData model

I'm encountering an issue when trying to store a SIMD3<Float> in a SwiftData model. Since SIMD3<Float> already conforms to Codable, I expected it to work. However, attempting to store a single SIMD3<Float> crashes with the following error:

Fatal error: Unexpected property within Persisted Struct/Enum: Builtin.Vec4xFPIEEE32

Interestingly, storing an array of vectors, [SIMD3<Float>], works perfectly fine. The issue only arises when trying to store a single SIMD3<Float>.

I’m not looking for a workaround (I can break the vector into individual floats in a custom codable struct to get by) , but I’d like to understand why storing a codable SIMD3<Float> in SwiftData results in this crash. Is this a limitation of SwiftData, or is there something I’m missing about how vectors are handled?

Any insights would be greatly appreciated!

Answered by DTS Engineer in 803705022

I think this is one of those cases where the why doesn’t matter [1]. If you need to do something and it doesn’t work, the path forward is clear: File a bug about that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Well, the why kinda matters when you go to file you bug, in that you choose to make it a bug report or an enhancement request. But it doesn’t really matter, because your feedback is going to be seen by the same folks either way.

It's interesting that the error says Vec4, not 3, isn't it?

I think this is one of those cases where the why doesn’t matter [1]. If you need to do something and it doesn’t work, the path forward is clear: File a bug about that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Well, the why kinda matters when you go to file you bug, in that you choose to make it a bug report or an enhancement request. But it doesn’t really matter, because your feedback is going to be seen by the same folks either way.

I think this is one of those cases where the doesn’t matter

Having said that, the whole ‘works when you put it in an array’ thing reminds me of the issue being discussed in this thread.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Issue storing SIMD3&lt;Float&gt; (and other simd’s) in a SwiftData model
 
 
Q