Local Packages and Feature Modules
Extracting features into local Swift packages for faster builds and isolation.
Local Packages and Feature Modules is a free Swift Academy lesson on CoddyKit — lesson 2 of 4. 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 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Feature Modules?
Splitting an app into local packages enforces encapsulation, speeds up incremental builds, and enables team parallel development.
// Without modules: one giant target recompiles everything
// With modules: changes to FeatureA only recompile FeatureACreating a Local Package
Create a directory beside your Xcode project and run swift package init inside it.
mkdir Features/UserProfile
cd Features/UserProfile
swift package init --name UserProfile --type libraryAdding to Xcode Project
Drag the local package directory into Xcode's project navigator. Xcode detects it as an SPM package automatically.
// In Xcode:
// File → Add Package Dependencies → Add Local...
// Select the package directoryReferencing a Local Package
In your app's Package.swift (or via Xcode), reference local packages with .package(path:).
.package(path: "../Features/UserProfile"),
// In the target:
.product(name: "UserProfile", package: "UserProfile")Public API Surface
Only public and open declarations in the local package are accessible from the app. Use access control to define the module boundary.
// UserProfile/Sources/UserProfile/ProfileView.swift
public struct ProfileView: View {
public init() {}
public var body: some View { Text("Profile") }
}Internal Implementation
All internal types are invisible outside the module, enforcing encapsulation automatically.
// Only visible within UserProfile module:
final class ProfileCache { ... }
struct ProfileMapper { ... }Feature Module Structure
Each feature module owns its own Domain, Data, and Presentation layers internally.
// UserProfile/
// ├── Sources/UserProfile/
// │ ├── Domain/ (entities, use cases, protocols)
// │ ├── Data/ (repositories)
// │ └── Presentation/ (views, view models)
// └── Tests/UserProfileTests/Shared Core Module
Extract cross-cutting concerns (networking, analytics, design system) into a shared module imported by feature modules.
// CoreNetwork package
// CoreDesign package
// Both imported by FeatureA and FeatureBDependency Graph
Feature modules should not depend on each other directly. Shared dependencies flow through a Core module to avoid coupling.
// GOOD:
// FeatureA → CoreNetwork
// FeatureB → CoreNetwork
// BAD:
// FeatureA → FeatureB (tight coupling)Build Time Benefits
With clean module boundaries, Xcode rebuilds only affected modules when source files change.
// Change in UserProfile → only UserProfile recompiles
// App target links the new binary → fast incremental buildTesting Feature Modules
Each feature module has its own test target, enabling parallel test execution and faster CI.
// Run all tests:
swift test --package-path Features/UserProfile
// Or let Xcode run them as part of the main test planQuick Check
What access level is required for declarations in a local Swift package to be usable from the app target?
Lesson Recap
Create local feature packages with swift package init, reference them via .package(path:), and expose only public types. Extract shared utilities into a Core module. Feature modules should not depend on each other. Clean module boundaries drastically reduce incremental build times.
Frequently asked questions
Is the “Local Packages and Feature Modules” lesson free?
Yes — the full text of “Local Packages and Feature Modules” is free to read here on the web, and the Swift Academy course includes 4 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 “Local Packages and Feature Modules”?
Extracting features into local Swift packages for faster builds and isolation. 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 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Local Packages and Feature Modules” 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
- Package.swift: Targets, Products and Dependencies
- Local Packages and Feature Modules
- Binary Targets and XCFrameworks
- Versioning, Resolving Conflicts and Swift Plugins