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:
不幸的是在线返回buildColumPart()我得到:
Missing argument for parameter #1 in call
What exactly does this mean and how do I fix it?
这究竟是什么意思,我该如何解决?
1 个解决方案
#1
13
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 )()。
#1
13
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 )()。