Sign up for FlowVella
Sign up with FacebookAlready have an account? Sign in now
By registering you are agreeing to our
Terms of Service
Loading Flow
The Swift Programming Language, Apple Inc.,
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html#//apple_ref/doc/uid/TP40014097-CH10-ID166
Functions are a
first-class type
Functions can optionally have external parameter names
Functions
func join(s1: String, s2: String, joiner: String) -> String {
return s1 + joiner + s2
}
join("hello", "world", ", ") //hello, world
//Default Value
func join(s1: String, s2: String, joiner: String = ", ") -> String {
return s1 + joiner + s2
}
join("hello", "world") //hello, world
//Overload with named parameters
func join(string s1: String, toString s2: String, withJoiner joiner: String = ", ") -> String {
return s1 + joiner + s2
}
join(string: "hello", toString: "world", withJoiner: ", ")
//Fails due to ambiguous overload
//var joinerFunc: (String, String, String) -> String = join