Tutorial by Examples

struct Mathematics { internal func performOperation(inputArray: [Int], operation: (Int)-> Int)-> [Int] { var processedArray = [Int]() for item in inputArray { processedArray.append(operation(item)) } retur...
func multiply2(item: Int)-> Int { return (item + 2) } let multiply2ToMe = multiply2 // passing the function directly to the function as param print(math.performOperation(inputArray: arrayToBeProcessed, operation: multiply2ToMe)) Output: [3, 5, 7, 9, 11, 13, 10, 8, 6, 4, 102] ...
// function as return type print(math.performComplexOperation(valueOne: 4)(5)) Output: 9

Page 1 of 1