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.
Why `import Foundation` Makes `exit(0)` Available
The exit(_:) function belongs to the platform C library, not Foundation. On Apple platforms, importing Foundation currently re-exports Darwin APIs, so this compiles:
import Foundation
exit(0)Do not rely on that indirect import for cross-platform command-line tools. Import the module that owns exit explicitly:
#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#endif
exit(EXIT_SUCCESS)For a successful natural return from main.swift, you can usually omit exit(0). Calling exit terminates immediately and skips pending defer blocks and object cleanup.
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 buildXcode: Framework Not Linked
In Xcode projects:
- Select your target → General → Frameworks, Libraries, and Embedded Content
- Add the missing framework
- Clean build folder:
Cmd+Shift+K
CocoaPods
# Podfile
pod 'Alamofire', '~> 5.8'pod install
# Open .xcworkspace, NOT .xcodeprojCommon 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 // PersistenceBridging 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
Track up to 100 issues per month on the free plan, with unlimited events and no credit card required.
Get Started FreeRelated Articles
Why Your Error Tracking Tool Doesn't Explain Errors (And What to Do About It)
Most error tracking tools show you stack traces but leave you guessing about root causes. Learn why AI-powered analysis changes everything.
Read moreHow to Fix Encoding Error in Rust
Learn how to fix the Encoding Error in Rust. Step-by-step guide with code examples.
Read moreFix Missing Import in Rails
Resolve NameError and LoadError in Rails applications, covering autoloading, Zeitwerk conventions, and gem dependency issues.
Read moreHow to Fix DatabaseError in Rails
Learn how to fix the DatabaseError in Rails. Step-by-step guide with code examples.
Read more