【发布时间】:2020-03-20 07:34:44
【问题描述】:
将我的代码更新到 iOS 13 和 Swift 5,我收到了这个弃用警告:
'withUnsafeBytes' 已弃用:改用
withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R
通过这段代码从 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 []
}
问题在于以下几行:
return vertexSource.data.withUnsafeBytes {
[SCNVector3](UnsafeBufferPointer<SCNVector3>(start: $0, count: count))
}
This answer 在此处发布了解决方案,但没有 Swift 5 代码,我无法为警告提出解决方案。
This other answer 和 this thread 似乎提供了解决方案,但仅适用于 UInt32 类型的值,而不是 [SCNVector3] (array)。
谢谢大家,我卡住了。
【问题讨论】:
标签: swift scenekit ios13 swift5 deprecation-warning