Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I use self in a func Swift

Tags:

swift

I'm trying to self to add SKSpriteNodes to the view in a function, but Xcode will not allow me to do so. It gives me the error "Use of unresolved identifier 'self'"

 func indicate() {
if test == 0 {
    var large = ((CGFloat(largest)*54) - 29) - selectedNode.position.x
    var small = selectedNode.position.x - ((CGFloat(smallest)*54) - 29)

    indicatorRight.position = CGPointMake(selectedNode.position.x + large, selectedNode.position.y)
    indicatorRight.userInteractionEnabled = true
    indicatorRight.zPosition = 0.5

    indicatorLeft.position = CGPointMake(selectedNode.position.x - small, selectedNode.position.y)
    indicatorLeft.userInteractionEnabled = true
    indicatorLeft.zPosition = 0.5


    println(indicatorLeft.position)
    //  println(smallest)
    self.addChild(indicatorRight)
    self.addChild(indicatorLeft)

    }


}
like image 681
Nas5296 Avatar asked Jun 12 '14 00:06

Nas5296


1 Answers

Make sure the method is presented in the Class open and closing braces

class A {

// You need to define a method here

}

// You might have declared it here.

like image 129
YSR fan Avatar answered Sep 17 '22 18:09

YSR fan