Programming in Swift: Functions & Types
Gain a deeper understanding of functions, practice using closures, and build your skills with named types. By Catie Catterwaul.
Learning path
This is part of the iOS and SwiftUI for Beginners learning path. View path.
Who is this for?
This is the fourth course in our iOS and Swift for Beginners learning path. You’re ready for this course if you’re working through that learning path in order, or you’re someone who has just a little bit of Swift experience.
To start, you’ll review some function fundamentals and learn more advanced features of functions. You’ll also practice writing closures, a close relative of functions, and using them to manipulate collections.
Then, you’ll move on to build your skills in writing named types: structures, classes, enumerations, and protocols. You’ll learn about the features they share, and some of the functionality that makes each unique.
Throughout the course, you’ll practice everything you learn with hands-on challenges.
This course isn’t suited for advanced developers. If that’s you, check out our Advanced Swift Courses for more ways to level-up your Swift skills!
Covered concepts
- Functions
- Overloading
- Closures
- Higher-Order Functions
- Enumerations
- Switch Statements
- Getters and Setters
- Property Observers
- Computed Properties
- Lazy Variables
- Methods
- Subclassing
- Initializers
- Protocols
- Extensions
Part 1: Functions
Find out what you’ll learn in this course, what you should know already, and how to get the most out of it.
Before you move on to some more advanced features of functions, review what you should already know.
Practice what you have learned about writing functions so far with this open-ended coding challenge.
When you create multiple functions with the same name, it’s called Overloading. Find out the rules to overloading functions.
Learn how to add variadic parameters to functions and how to use the input keyword to mutate parameters in a function.
Practice what you have learned about function overloads and parameters with this series of hands-on coding challenges.
Functions are really just another type of data in Swift! You can use them as parameters for other functions.
Review what you learned about functions in this part of the course, and see what is coming up in the next part.
Part 2: Closures
In this part of the course you’ll learn about Swift closures, and how they can help you deal with collections.
See what closures and functions have in common, and find out about some key differences between the two.
Practice what you have learned about writing closures with this series of hands-on coding challenges.
Closures coming with a dizzying arraying of syntactical options! Learn how to read and write them all in this episode.
Practice writing closures using different levels of verbosity with this series of hands-on coding challenges.
Find out how writing closures can help you handle collections with two common alternatives to for loops: forEach and map!
Try out two specialized mapping methods that help you deal with collections of optionals and multidimensional collections!
Practice what you have learned about using closures and collection with this series of hands-on coding challenges.
Learn to use three more methods to help you filter and sort collections, and use all elements in a collection with reduce.
Practice what you have learned about filter, reduce, and sort with this series of hands-on coding challenges.
Review what you learned about closures and how they can help you with collection, and see what is coming up in the next part.
Part 3: Enumerations
In this part of the course you’ll learn what enumerations are, and how they can work together with switch statements.
Learn how to use enumerations to represent a specific set of related, discrete values like card suits or seasons.
Practice what you have learned about using enumerations with this series of hands-on coding challenges.
Switch statements are another method of control flow like loops and if statements. Find out how they can help you deal with enumerations.
You can use switch statements to switch on types other than enumerations! Try it out in this episode.
Practice what you have learned about switch statements with this series of hands-on coding challenges.
There’s another way to associate values with your enumeration instances. They are literally called “associated values”.
Review what you learned about enumerations and switch statements, and see what is coming up in the next part.
Part 4: Properties & Methods
In this part of the course, you’ll study some features shared by named types: properties and methods!
Learn more about stored properties, like how to use property observers, getters and setters, and type properties.
In this episode, learn about a different kind of property that is recomputed every time it is accessed!
In this episode, learn about the lazy keyword and how it can help you avoid expensive calculations until you need them.
Practice what you have learned about using different kinds of properties with this series of hands-on coding challenges.
Take a deep dive into methods, including writing initializers, mutating methods, and more. Work with structures and enumerations!
Practice what you have learned about using methods through this series of hands-on coding challenges.
In this episode, learn when it is best to use computed properties, and when it’s best to use methods.
Review what you learned about properties and methods in this part of the course, and find out what’s up next.
Part 5: Protocols & Inheritance
In this part of the course, learn how you can use subclassing and protocol adoption to let your types inherit functionality.
Learn about a unique features of Swift classes that lets one class inherit functionality from another class.
Practice what you’ve learned about subclassing with these hands-on challenges about Swift class inheritance.
Learn how to create your own class initializers, including two-phase initialization, and required vs. convenience initializers.
Practice what you’ve learned about initializers by creating your own class initializers, with some hands-on challenges.
Learn how to make your types conform to protocols in Swift, which you can think of as a to-do list for your types.
Swift extensions can help you add functionality to named types, and give your protocols more power with default implementations!
Practice what you have learned about protocols and extensions in this series of hands-on challenges.
Review the differences between classes and structures in Swift, and when you might want to subclass or use a protocol.
You’ve learned a ton of new Swift concepts! Find out where to go next with all of your new knowledge!