Swift Academy · Lesson

Importing modules & semantic versioning basics

Learn how to import external modules, declare dependencies in Package.swift, and manage them with semantic versioning rules.

Lesson 3 of 38 steps

Importing modules & semantic versioning basics is a free Swift Academy lesson on CoddyKit. This is lesson 3 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, and your progress syncs across the web and the CoddyKit app. The Swift Academy course includes 3 lessons in total.

Overview

This lesson shows how to import modules, declare dependencies, and use semantic versioning rules in SwiftPM.

Import basics

Use import to bring in standard or package modules for use in your code.

// Example main.swift
import Foundation   // standard module
import MyLib        // custom module from Sources or dependency

print("Modules imported!")

Dependency declaration

In Package.swift, list external dependencies with .package(...) and a version rule.

// Package.swift snippet
dependencies: [
    .package(url: "https://github.com/apple/example-package-dealer.git",
             from: "1.2.0")
]

upToNextMajor

upToNextMajor allows updates until the next major version. This ensures backward compatibility but avoids breaking changes.

// Accept >=1.2.0 but <2.0.0
.package(url: "https://github.com/apple/example.git",
         .upToNextMajor(from: "1.2.0"))

Other rules

Other rules: .exact locks to one version; .upToNextMinor allows safe updates within the minor series.

// Exact version
.package(url: "url", .exact("1.2.3"))

// Up to next minor
.package(url: "url", .upToNextMinor(from: "1.2.0"))

Products & imports

Targets must be exposed as products to be imported by other packages or executables.

// Package.swift
products: [
    .library(name: "MyLib", targets: ["MyLib"]),
    .executable(name: "Tool", targets: ["Tool"])
]

// Code
import MyLib
print(MyLib.someFunc())

Version rule

Quick check: What does .upToNextMajor(from: "1.2.0") mean?

Recap

Recap: Use import to access modules, declare dependencies in Package.swift, and control updates with semantic versioning rules like upToNextMajor.

Free to start

Learn Swift with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
122
Lessons
409

Frequently Asked Questions

Is the “Importing modules & semantic versioning basics” lesson free?

Yes — any 3 lessons of the Swift Academy learning path, including “Importing modules & semantic versioning basics”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Swift Academy course includes 3 lessons in total.

What will I learn in “Importing modules & semantic versioning basics”?

Learn how to import external modules, declare dependencies in Package.swift, and manage them with semantic versioning rules. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 3.

How long does the “Importing modules & semantic versioning basics” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Swift Package Manager basics
  2. Layout, products & build/test/run
  3. Importing modules & semantic versioning basics
← Back to Swift Academy