Links

Variadic Functions | Go by Example - Swift 3.0

Variadic functions can be called with any number of trailing arguments. Same like print(...) for Swift. Can be used with define type e.g. "String, Int.." or Any protocol.

/// variadic
func variadic (any: Any...) {
    
    if any.isEmpty {
        return
    }

    for val in any {
        print(val)
    }

}

variadic(any: "hello", "world", 2017, 2.0)


Post a Comment