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.
Defining functions like variables - Swift Tutorial
From the course: Learning Functional Programming with Swift
Defining functions like variables
- [Instructor] So now that we know what the function types look like, let's see how we actually define the function using an equals sign. To start let's open up this starter code. The first thing that we can do is define these functions as an existing function. So for example, if we already had a function called number of characters which takes a string and returns the number of characters in it, it'll take one argument called string which is a string type and return an integer, the number of characters in the string. And finally inside will return the number of characters, return string dot count. Then we can simply say equals number of characters. Finally we can call our character count function that we just defined like this, character count hello and we see that we get our answer over to the right. Another thing that we can do is define our new function with a closure. In Swift, a closure is just a nameless function that we can define on the spot. The syntax for a closure is like…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.