Skip to content

Swift Modules

New Course Coming Soon:

Get Really Good at Git

You write software in files.

A simple program might be stored in a single file, but complex programs are written across multiple files.

Swift provides a way to group several files into a group, called module.

Modules helps us do 2 things: reuse code, and encapsulate code.

You just have to write a particular functionality once, and after putting it into a module, you can import that into different places and projects.

Encapsulation means that the library can do lots of complicated things internally, but you only expose a tiny bit of it to the outside.

You start using modules by importing them.

If you’ve ever written

import SwiftUI

or

import UIKit

you’ve already used modules. Frameworks like UIKit and SwiftUI, and many others, are modules.

After you import a module, everything that that module declares public will be visible inside your application code.

Modules can import other modules, and when this happens you have access to those modules automatically.

For example SwiftUI imports Foundation, so you don’t have to write

import SwiftUI
import Foundation

because you just need the first line.

Your application is a module, too.

Swift itself is a module, as well. And you never have to import Swift because it’s done automatically for you.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Get my Swift Handbook

Here is how can I help you: