0Pricing
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.

Importing modules & semantic versioning basics is a free Swift Academy lesson on CoddyKit — lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.

Frequently asked questions

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

Yes — the full text of “Importing modules & semantic versioning basics” is free to read here on the web, and the Swift Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

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; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.

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