Skip to content
Learn Netverks

Lesson

Step 29/36 81% through track

modules-imports-swift

Modules and imports

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Modules and imports: the syntax, patterns, and safety habits you need before advancing in Swift.

Teams still ship Modules and imports in Swift codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Modules and imports in contexts like: iPhone/iPad/Mac apps, server-side Swift (niche), and Apple toolchain projects.

Write Swift in main.swift with print(), click Run on server—the dev runner swiftc compiles and runs the binary (requires Swift toolchain, typically macOS; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Swift code organizes into modules—each target (app, framework, library) is a module with its own namespace. import brings another module’s public API into scope.

Import rules

import Foundation
// import UIKit  // needs iOS SDK — use locally in Xcode

The playground allows Foundation; UIKit/SwiftUI require Apple SDK targets locally.

Access control

  • private — enclosing declaration
  • fileprivate — same source file
  • internal — same module (default)
  • public / open — exported to clients

Important interview questions and answers

  1. Q: Module vs package?
    A: Module is a compiled unit; Swift Package Manager groups modules into packages with dependencies.
  2. Q: public vs open?
    A: open allows subclassing and overriding outside the module; public is read-only outside for classes.

Self-check

  1. What is the default access level?
  2. Why avoid UIKit import in sandbox code?

Tip: Default access is internal—use public only for API surface exported to other modules.

Interview prep

Default access?

internal—visible within the same module.

public vs open?

open allows subclassing outside module; public does not for classes.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • import vs @testable?
  • Access control levels?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump