So far, we’ve used several data types, including Int, Double, String, and Bool. We’ve even created our own “type” using structs to make blueprints and templates for objects in our program.

Besides structures, Swift has another construct that also serves as a blueprint or template for an object, a class! A class also defines the characteristics and behaviors of an object. While they feel and behave very similarly, classes come with additional quirks that structures don’t have:

  • Inheritance enables one class to inherit the characteristics of another class.
  • Classes are reference types while structures are value types.

Suppose a company called Hooli gives out ID badges to its employees. Somewhere down the line, the powers that be decide to have a variation of the badges made just for all the managers.

So instead of creating the new badge template from scratch, we would use the employee badge template to create the manager badge template — that’s inheritance! Because managers are still employees, but also have their own special security clearance.

We will explore these differences a bit more, but first, let’s get classy with Swift!


Press Next to continue.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?