Missing argument for parameter # 1 in call

I have a lazy parameter that I am trying 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 the return buildColumPart() I get:

 Missing argument for parameter #1 in call 

What exactly does this mean and how to fix it?

+6
source share
1 answer

You need to use self to access instance methods in lazy properties:

 class ColumnNode: SCNNode { lazy var upperColumnNode: SCNNode = { return self.buildColumPart() }() func buildColumPart() -> SCNNode { var node = SCNNode() ... return node } } 

Interestingly, the reason he complains about parameter # 1 is because instance methods are actually class methods that take an instance as a parameter and return a closure with the captured instance - instead of self.buildColumPart() you could instead this call buildColumPart(self)() .

+13
source

Source: https://habr.com/ru/post/977690/


All Articles