Updating my code to iOS 13 and Swift 5, I have this deprecated warning:
'withUnsafeBytes' is deprecated: use
withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R
instead
Over this fragment of code to extract the vertices from a SCNGeometry:
/// Extracts vertices from SCNGeometry
func vertices() -> [SCNVector3] {
let vertexSources = self.sources(for: SCNGeometrySource.Semantic.vertex)
if let vertexSource = vertexSources.first {
let count = vertexSource.data.count / MemoryLayout<SCNVector3>.size
return vertexSource.data.withUnsafeBytes {
[SCNVector3](UnsafeBufferPointer<SCNVector3>(start: $0, count: count))
}
}
return []
}
The problem lays inside this lines:
return vertexSource.data.withUnsafeBytes {
[SCNVector3](UnsafeBufferPointer<SCNVector3>(start: $0, count: count))
}
This answer gives solution here posted but there is no Swift 5 code, and I cannot come up with a solution for the warning.
This other answer and this thread seem to give a solution but for only a value of type UInt32
not an [SCNVector3]
(array).
Thank you all, I'm stuck.