In iOS, extensions are a clean and structured way to add functionality to an existing type. Extensions can be used on any type in iOS, including classes, structs, enums, and protocols.

Extensions are very powerful because not only do they allow us to add functionality to our own custom types, but also to types provided by libraries and frameworks (including Apple's frameworks)!

To extend a type, we use the extension keyword. For instance, if we wanted to use a specific blue color in our application, we could extend the UIColor class (which is provided by Apple's UIKit framework) to include the following type method:

extension UIColor {
  static func blueApplicationColor() {

Now when we want to access our special blue color, all we have to do is:


Oftentimes we use extensions to conform to protocols; we do this to keep our code clean and organized. For example, if we had a class named CustomViewController and wanted it to conform to the UITableViewDataSource protocol, we would define CustomViewController as follows:

extension CustomViewController: UITableViewDataSource {

Now when we implement the properties and methods defined in the UITableViewDataSource protocol, we will do so in one centralized place, inside the extension. This makes it easier to find code later on should we need to make changes or debug.


If you have feedback on this tutorial or find any mistakes, please open issues on the GitHub Repository or comment below.

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations in San Francisco and Asia

Find your location

Product College

A computer science college

Graduate into a successful career as a founder or software engineer.

Learn more

Cookies on Make School's website

We have placed cookies on your device to ensure that we give you the best experience on our website.

This site uses cookies to deliver our services. By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Your use of Make School’s Products and Services is subject to these policies and terms.

Please note that Make School no longer supports Internet Explorer

We recommend upgrading to a modern web browser. Learn more