All posts

Fix Missing Import in Swift

Resolve 'No such module' and missing import errors in Swift projects, covering SPM dependencies, framework linking, and module maps.

Missing Import Errors in Swift

Swift's No such module 'X' error means the compiler can't find the module. This is usually a dependency configuration issue, not a missing import statement.

Swift Package Manager

// Package.swift
let package = Package(
    name: "MyApp",
    dependencies: [
        .package(url: "https://github.com/Alamofire/Alamofire", from: "5.8.0"),
    ],
    targets: [
        .target(
            name: "MyApp",
            dependencies: ["Alamofire"]),  // Must list here too!
    ]
)
swift package resolve
swift build

Xcode: Framework Not Linked

In Xcode projects:

  1. Select your target → General → Frameworks, Libraries, and Embedded Content
  2. Add the missing framework
  3. Clean build folder: Cmd+Shift+K

CocoaPods

# Podfile
pod 'Alamofire', '~> 5.8'
pod install
# Open .xcworkspace, NOT .xcodeproj

Common Swift Imports

import Foundation     // Strings, dates, networking basics
import UIKit          // iOS UI (not available on macOS)
import SwiftUI        // Declarative UI
import Combine        // Reactive programming
import CoreData       // Persistence

Bridging Header for Objective-C

If importing an ObjC library:

// MyApp-Bridging-Header.h
#import <SomeObjCLib/SomeObjCLib.h>

Then use it directly in Swift without an import statement.

Bugsly's iOS SDK captures runtime crashes with symbolicated stack traces, including module load failures that might not surface until a specific code path is executed.

Try Bugsly Free

AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.

Get Started Free