提问人:senkuu 提问时间:11/12/2023 更新时间:11/12/2023 访问量:23
条件绑定的初始值设定项必须具有可选类型,而不是“SCNNode”ARKit
Initializer for conditional binding must have Optional type, not 'SCNNode' ARKit
问:
//ARFace geometry update
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
guard let faceAnchor = anchor as? ARFaceAnchor,
let contentController = faceAnchorAndContentControllers[faceAnchor],
let contentNode = contentController.contentNode else {
return
}
遇到同样的问题。我应该在这里更改什么?
有人可以解释我的错误在哪里吗?
答:
-2赞
Surajkumbhar904
12/6/2023
#1
可能是字典没有返回可选的。您需要对代码进行少量修改,如下所示:faceAnchorAndContentControllers[faceAnchor]
SCNNode
struct Controller{
let contentNode: SCNNode?
}
var faceAnchorAndContentControllers : [ARFaceAnchor : Controller] = [:]
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
guard let faceAnchor = anchor as? ARFaceAnchor,
let contentController = faceAnchorAndContentControllers[faceAnchor],
let contentNode = contentController.contentNode else {
return
}
}
评论
0赞
Jack Goossen
12/8/2023
将某些东西设置为可选只是为了满足错误地认为它是可选的代码是没有帮助的(你使它变得更糟)。合乎逻辑的解决方案是将非可选项移到保护子句之外。
评论