We introduce how to define functions like variables in Swift. We then go through some examples of how this might be used in Swift and a few pitfalls.
- [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 this,…we say equals bracket and then we define our arguments,…
- What is functional programming?
- Keeping functions and data separate
- First-class functions
- Working with arrays functionally
- Filtering and reducing
- Partial-application and recursion
Skill Level Intermediate
Swift 4: Protocol-Oriented Programmingwith Károly Nyisztor1h 44m Intermediate
Swift: Delegations and Data Sourceswith Steven Lipton1h 6m Intermediate
Swift: Writing Reusable Frameworkswith David Okun1h 49m Intermediate
1. What Is Functional Programming?
2. First-Class Functions
3. Array Functions
4. Advanced Functional Concepts
Next steps1m 1s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.