[英]Missing argument for parameter #1 in call
I have a lazy parameter that I'm attempting to call a helper function in: 我有一个懒惰的参数,我试图调用辅助函数:
class ColumnNode: SCNNode {
lazy var upperColumnNode: SCNNode = {
return buildColumPart()
}()
func buildColumPart() -> SCNNode {
var node = SCNNode()
...
return node
}
}
Unfortunately on line return buildColumPart()
I am getting: 不幸的是在线return buildColumPart()
我得到:
Missing argument for parameter #1 in call
What exactly does this mean and how do I fix it? 这究竟是什么意思,我该如何解决?
You need to use self
to access instance methods in lazy properties: 您需要使用self
来访问延迟属性中的实例方法:
class ColumnNode: SCNNode {
lazy var upperColumnNode: SCNNode = {
return self.buildColumPart()
}()
func buildColumPart() -> SCNNode {
var node = SCNNode()
...
return node
}
}
Interestingly enough, the reason it's complaining about parameter #1 is that instance methods are actually class methods that take an instance as a parameter and return a closure with the instance captured - instead of self.buildColumPart()
, you could instead call buildColumPart(self)()
. 有趣的是,它抱怨参数#1的原因是实例方法实际上是类方法,它将实例作为参数并返回一个捕获实例的闭包 - 而不是self.buildColumPart()
,你可以改为调用buildColumPart(self)()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.