From the course: Learning Functional Programming with Swift

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Passing functions as arguments

Passing functions as arguments - Swift Tutorial

From the course: Learning Functional Programming with Swift

Start my 1-month free trial

Passing functions as arguments

- [Instructor] Now that we've seen how we can define functions in the same way that we can define other types, the next step is to look at how we can pass functions as arguments to other functions. When we create a function that takes other things such as strings or integers as arguments, we have to specify the argument types in the function definition like this. If we have a function that takes a string and prints it uppercased, it will look like this. Function print uppercased. Takes a string as an argument. String. Doesn't return anything. And inside the function we say print string dot uppercased. Parentheses. Then we call this function like this. Print uppercased. String. Hello. So we're used to passing an argument with the purpose of specifying what the data is that we're operating on, but what if instead of passing arguments into our function to specify what our data is, we could pass an argument to specify what was done to our data? This is one of the important things that…

Contents