我有两个代码块
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
// BLOCK 1 Which is not working
guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
var plane = Plane(with: planeAnchor) //IT IS SUBCLASS OF SCNNode
var geo = plane.geometry
plane.transform = SCNMatrix4MakeRotation(-.pi / 2, 1, 0, 0)
update(&plane, withGeometry: plane.geo, type: .static)
//Up here Cannot pass immutable value as inout argument: implicit conversion from 'Plane' to 'SCNNode' requires a temporary
node.addChildNode(plane)
// BLOCK 2 Which is working
let width = CGFloat(planeAnchor.extent.x)
let height = CGFloat(planeAnchor.extent.z)
let plane1 = SCNPlane(width: width, height: height)
plane1.materials.first?.diffuse.contents = UIColor.white.withAlphaComponent(0.5)
var planeNode = SCNNode(geometry: plane1)
let x = CGFloat(planeAnchor.center.x)
let y = CGFloat(planeAnchor.center.y)
let z = CGFloat(planeAnchor.center.z)
planeNode.position = SCNVector3(x,y,z)
planeNode.eulerAngles.x = -.pi / 2
update(&planeNode, withGeometry: plane1, type: .static)
// WORKING FINE
node.addChildNode(planeNode)
self.planes[anchor.identifier] = plane
}
块1
class Plane: SCNNode
当我尝试将它的对象传递给需要inout
它向我显示错误的函数时,我有子类
无法将不可变值作为 inout 参数传递:从“Plane”到“SCNNode”的隐式转换需要临时
虽然如果我删除子类,那么它工作正常
为什么这是快速错误或我遗漏了什么?