Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing argument for parameter #1 in call

Tags:

ios

swift

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:

Missing argument for parameter #1 in call

What exactly does this mean and how do I fix it?

like image 596
Kyle Decot Avatar asked Nov 04 '14 04:11

Kyle Decot


1 Answers

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 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)().

like image 175
Nate Cook Avatar answered Sep 29 '22 09:09

Nate Cook