Default Parameters and Type Annotation
Swift support default Default Parameter for functions
You can define a default value for any parameter as part of a function’s definition. If a default value is defined, you can omit that parameter when calling the function.
Quick simple example
This is pretty easy example. We don't provide any argument to the function so default value is used.
Let's try this one
The result is Drive fast. Use nitro: false
.
What happens here is:
- Because of polymorphism
RaisingCar
drive function is being called
- But it's called with
false
default parameter. This happens because swift binds default parameters statically. The static type of rasing2 variable is Car, because we have specified it.
Thanks to Airspeed Velocity about Great post