0

I'm trying to secure encode a SceneKit SCNMatrix4 so it conforms to NSSecureCoding with something akin to the following:

if let transform = aDecoder.decodeObject(of: SCNMatrix4.self, forKey: DATA_KEY_TRANSFORM) {
    self.transform = transform            
}

But this throws-up the compile error:

Cannot convert value of type 'SCNMatrix4.Type' to expected argument type '[AnyClass]?' (aka 'Optional>')

Obviously SCNMatrix4 is not an object & is the reason why this doesn't work, but surely I don't need to go through every single one of the 16 Floats in the SCNMatrix4 and encode each with:

aDecoder.decodeFloat(forKey: "someKey")

Surely not?

What is the correct way to secure encode this?

Geoff H
  • 3,107
  • 1
  • 28
  • 53

2 Answers2

1

I suggested one way as following, as same as in swiftShot examples:

SCNMatrix4 = SCNMatrix.init(float4x4)

float4x4 <= self.column[0] = float4

self.column[1] = float4
self.column[2] = float4
self.column[3] =  float4

float4 <= with_4_Float.

E.Coms
  • 11,065
  • 2
  • 23
  • 35
1

Coding will require you to wrap the matrix into a NSValue first, and then unwrap it. See init(scnMatrix4:) and scnMatrix4Value.

mnuages
  • 13,049
  • 2
  • 23
  • 40