How does one print NSValue bytes? When using print it doesn't print all the bytes and puts '...'. E.g. {length = 128, bytes = 0x00000000 0000f03f 00000000 00000000 ... 00000000 0000f03f }
import Cocoa
import SceneKit
var identityMatrix = SCNMatrix4()
identityMatrix.m11 = 1
identityMatrix.m12 = 0
identityMatrix.m13 = 0
identityMatrix.m14 = 0
identityMatrix.m21 = 0
identityMatrix.m22 = 1
identityMatrix.m23 = 0
identityMatrix.m24 = 0
identityMatrix.m31 = 0
identityMatrix.m32 = 0
identityMatrix.m33 = 1
identityMatrix.m34 = 0
identityMatrix.m41 = 0
identityMatrix.m42 = 0
identityMatrix.m43 = 0
identityMatrix.m44 = 1
var a = [NSValue]()
a.append(NSValue(scnMatrix4:identityMatrix))
identityMatrix.m11 = 1
identityMatrix.m12 = 0
identityMatrix.m13 = 0
identityMatrix.m14 = 0
identityMatrix.m21 = 0
identityMatrix.m22 = 1
identityMatrix.m23 = 0
identityMatrix.m24 = 0
identityMatrix.m31 = 0
identityMatrix.m32 = 0
identityMatrix.m33 = 1
identityMatrix.m34 = 0
identityMatrix.m41 = 0
identityMatrix.m42 = -1.0
identityMatrix.m43 = 0
identityMatrix.m44 = 1
a.append(NSValue(scnMatrix4:identityMatrix))
print(a[0])
First of all, we can tidy this up by using an array literal, and the
SCNMatrix4initializer to get rid of all the mutability:That makes the code much more sensible. We can also notice from the documentation that there's already a constant that we can use to get an identity matrix:
It's not clear why these matrices are wrapped in
NSValue, but to display details about them (and call other methods on them), you'll need to fish the matrix back out of theNSValuebox using thescnMatrix4ValueAPI:If you want to print the byte layout of these, (although it's still really not clear why you would want this, since AFAICT,
NSValueandSCNMatrix4make no promises about their memory layout), you can use the usual pointer APIs, in combination with some hex printing logic such as this:prints: