Tuesday 8 July 2014

Calling a Method in iOS Swift: Takes and Returns multiple values





A function type can have a variadic parameter as the last parameter in its parameter type. Syntactically, a variadic parameter consists of a base type name followed immediately by three dots (...), as in Int.... A variadic parameter is treated as an array that contains elements of the base type name. For instance, the variadic parameter Int... is treated as [Int]. For an example that uses a variadic parameter, see Variadic Parameters.

To specify an in-out parameter, prefix the parameter type with the inout keyword. You can’t mark a variadic parameter or a return type with the inout keyword. In-out parameters are discussed in In-Out Parameters.

The type of a curried function is equivalent to a nested function type. For example, the type of the curried function addTwoNumbers()() below is (Int, Int) -> (Int, NSString, Int):

// Method Declaration in Swift Language:
func addTwoNumbers(a: Int, b: Int) -> (Int, NSString, BOOL)
{ 
return ((a + b), "Addition", True)
}

// Method Calling in Swift Language:
var (value, strValue, isTrue) = addTwoNumbers(4, 5) // Returns 9,Addition and TRUE





No comments:

Post a Comment