From the course: Learning Higher-Order Functions with Swift

Unlock the full course today

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

Closures and function types

Closures and function types

From the course: Learning Higher-Order Functions with Swift

Start my 1-month free trial

Closures and function types

- [Instructor] So we've been talking about closures and functions and how functions are closures with names. Well also, it's important to understand that closures and functions have types. In fact, there are first class types in Swift. So they also can be types for parameters in functions. Well, what do you do with parameters in functions? You pass them in, so they can be passed around. Again, going back to the definition of a closure; it can be passed around. So our examples before had a type, they took two Ints and returned an Int and it looks just like this: Int-Int-returns-Int. At least that's how I say it. What do I know? I used to say ASCII was a a-s-c-two, I thought it was Roman numerals. I read everything, so that's usually how I pronounce it. So I would say the type of those closures were Int-Int-return-Int. So this function has a type, it takes two parameters a String and an Int returns a String. So I would say that type is String-Int-returns-String, that's its type and just…

Contents