0

I'm trying to learn Swift, and this has me really confused:

Say you're adding a gesture:

        faceView.addGestureRecognizer(UIPinchGestureRecognizer(target: faceView, action: "scale:")) 

And this is the scale function:

func scale(gesture: UIPinchGestureRecognizer) {

    if gesture.state == .Changed {
        scale *= gesture.scale
        gesture.scale = 1
    }

}

Why is there a colon at the end of scale (e.g. action:"scale:")? Is it to reference the fact that the scale function takes in a parameter of type UIPinchGestureRecognizer?

If it is, then how does the colon represent that parameter?

comp_sci5050
  • 145
  • 2
  • 11
  • Possible duplicate of [@selector() in Swift?](http://stackoverflow.com/questions/24007650/selector-in-swift) – Rashwan L Jan 06 '16 at 21:11
  • 1
    @RashwanL would'nt say duplicate, but very related. Also related: [When to use a colon with a selector](http://stackoverflow.com/questions/4953623/when-to-use-a-colon-with-a-selector) – tskulbru Jan 06 '16 at 21:13

1 Answers1

1

The gesture recognizer is the parameter. By specifying a colon you say you want to have the type (the recognizer) sent as a parameter, just as you thought. If you omit said colon, you would need to have a function without the recognizer as a parameter.

tskulbru
  • 2,336
  • 1
  • 20
  • 38