I bit the bullet and started converting my app to Swift 3. As always, the converter leaves very much to be desired. In this case, I'm not sure how to properly code the new version. Here is the original:
let indexes : [CInt] = [0,1,2,3]
let dat = NSData(bytes: indexes, length: sizeofValue(indexes))
let ele = SCNGeometryElement(data:dat, primitiveType: .Triangles, primitiveCount: 2, bytesPerIndex: sizeof(Int))
After running the conversion and writing a new sizeof (thanks), I ended up with this:
let indexes : [CInt] = [0,1,2,3]
let dat = Data(bytes: UnsafePointer<UInt8>(indexes), count: sizeof(indexes))
let ele = SCNGeometryElement(data:dat, primitiveType: .triangles, primitiveCount: 2, bytesPerIndex: MemoryLayout<Int>.size)
However, this gives me (on the Data(bytes:length:)
call):
'init' is unavailable: use 'withMemoryRebound(to:capacity:_)' to temporarily view memory as another layout-compatible type.
I've looked over a few threads here, and read the release notes that cover this, and I'm still baffled what I'm supposed to do here.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…