Programming in Swift: Functions and Types

Gain a deeper understanding of functions, practice using closures, and build your skills with named types. By Catie Catterwaul.

Login to leave a rating/review
Download materials
Save for later
Share

Who is this for?

This course is part of 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

1
Toggle description

Find out what you'll learn in this course, what you should know already, and how to get the most out of it.

Toggle description

Before you move on to some more advanced features of functions, review what you should already know.

Toggle description

Practice what you have learned about writing functions so far with this open-ended coding challenge.

Toggle description

When you create multiple functions with the same name, it's called "Overloading". Find out the rules to overloading functions.

Toggle description

Learn how to add variadic parameters to functions and how to use the inout keyword to mutate parameters in a function.

Toggle description

Practice what you have learned about function overloads and parameters with this series of hands-on coding challenges.

Toggle description

Functions are really just another type of data in Swift! You can use them as parameters for other functions.

Conclusion 0:26
Toggle description

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

Toggle description

In this part of the course you'll learn about Swift closures, and how they can help you deal with collections.

Closures 7:52
Toggle description

See what closures and functions have in common, and find out about some key differences between the two.

Toggle description

Practice what you have learned about writing closures with this series of hands-on coding challenges.

Toggle description

Closures coming with a dizzying arraying of syntactical options! Learn how to read and write them all in this episode.

Toggle description

Practice writing closures using different levels of verbosity with this series of hands-on coding challenges.

Toggle description

Find out how writing closures can help you handle collections with two common alternatives to for loops: forEach and map!

Toggle description

Try out two specialized mapping methods that help you deal with collections of optionals and multidimensional collections!

Toggle description

Practice what you have learned about using closures and collection with this series of hands-on coding challenges.

Toggle description

Learn to use three more methods to help you filter and sort collections, and use all elements in a collection with reduce.

Toggle description

Practice what you have learned about filter, reduce, and sort with this series of hands-on coding challenges.

Conclusion 3:57
Toggle description

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

Toggle description

In this part of the course you'll learn what enumerations are, and how they can work together with switch statements.

Toggle description

Learn how to use enumerations to represent a specific set of related, discrete values like card suits or seasons.

Toggle description

Practice what you have learned about using enumerations with this series of hands-on coding challenges.

Toggle description

Switch statements are another method of control flow like loops and if statements. Find out how they can help you deal with enumerations.

Toggle description

You can use switch statements to switch on types other than enumerations! Try it out in this episode.

Toggle description

Practice what you have learned about switch statements with this series of hands-on coding challenges.

Toggle description

There’s another way to associate values with your enumeration instances. They are literally called “associated values”.

Conclusion 0:33
Toggle description

Review what you learned about enumerations and switch statements, and see what is coming up in the next part.

Part 4: Properties & Methods

Toggle description

In this part of the course, you'll study some features shared by named types: properties and methods!

Toggle description

Learn more about stored properties, like how to use property observers and type properties.

Toggle description

In this episode, learn about a different kind of property that is recomputed every time it is accessed!

Toggle description

In this episode, learn about the lazy keyword and how it can help you avoid expensive calculations until you need them.

Toggle description

Practice what you have learned about using different kinds of properties with this series of hands-on coding challenges.

Methods 13:43
Toggle description

Take a deep dive into methods, including writing initializers, mutating methods, and more. Work with structures and enumerations!

Toggle description

Practice what you have learned about using methods through this series of hands-on coding challenges.

Toggle description

In this episode, Learn when it is best to use computed properties, and when it's best to use methods.

Conclusion 0:55
Toggle description

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

Toggle description

In this part of the course, learn how you can use subclassing and protocol adoption to let your types inherit functionality.

Inheritance 15:05
Toggle description

Learn about a unique features of Swift classes that lets one class inherit functionality from another class.

Toggle description

Practice what you've learned about subclassing with these hands-on challenges about Swift class inheritance.

Initializers 13:26
Toggle description

Learn how to create your own class initializers, including two-phase initialization, and required vs. convenience initializers.

Toggle description

Practice what you've learned about initializers by creating your own class initializers, with some hands-on challenges.

Protocols 6:41
Toggle description

Learn how to make your types conform to protocols in Swift, which you can think of as a to-do list for your types.

Toggle description

Swift extensions can help you add functionality to named types, and give your protocols more power with default implementations!

Toggle description

Practice what you have learned about protocols and extensions in this series of hands-on challenges.

Toggle description

Review the differences between classes and structures in Swift, and when you might want to subclass or use a protocol.

Conclusion 1:08
Toggle description

Congratulations on finishing the course - you've learned a ton of new Swift concepts! Find out where to go next with all of your new knowledge.