From the course: Learning Higher-Order Functions with Swift

Unlock the full course today

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

Passing functions

Passing functions

From the course: Learning Higher-Order Functions with Swift

Start my 1-month free trial

Passing functions

- [Instructor] As I've mentioned before, functions are just named closures and you can pass in a function anywhere you can pass in a closure. It's all about the type. Just like what we say with sort, but type was a function that takes two strings and returns a boolean or two ints and returns a boolean, well that's what the less than operator does. So, you can pass that in. So if you write a function that satisfies the type that needs to be pass in, you can pass in that function. So you want to try that out? I know you do. Let's do it. So back in Xcode, we'll take one of these examples We'll do firstLongName. And I'm going to run that and I'm going to remove this print on line three so that it just prints out optional Jenna. And I'm going to put in hits no coalescing operator 'cause I don't like the warnings and I don't like the optional. So I'll say no val there and when I run it, it's going to say just Jenna. Okay so we went to write a function that has the same signature, takes a…

Contents