edit: after this post originally went up, the Swift dev team confirmed on the forums that default parameters should be dynamically bound. However, as of Swift 1.1, they’re still statically bound.

Quick quiz. What does the following code do?

class Shape { func draw(colour: String = "Red") { println("\(colour) shape") } } let s1 = Shape() s1.draw()

It prints Red shape , right? No argument supplied, so the default value of Red is used.

Ok what about this?

class Circle: Shape { override func draw(colour: String = "Blue") { println("\(colour) circle") } } let s2 = Circle() s2.draw()

It should Blue circle . No surprises there. Again no argument, but the overridden function defaults to a different color and prints a different shape.

Ok finally, what about this?

let s3: Shape = Circle() s3.draw()

Blue circle again, right? s3 ‘s static type is the base class, but it points to an inherited class. Polymorphism means the overridden function runs, so it should be just like the previous example.

If Swift bound default parameters dynamically, sure. But as of Swift 1.1, it behaves like C++,1 and you actually get Red circle . This is because parameters are bound statically not dynamically. Similarly, which overloaded function is chosen is also done statically – as seen in our series on Swift overload resolution