Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

A module import in Swift is an import declaration that brings the public interface of an external module—such as a framework, library, or application—into the lexical scope of the current source file. This mechanism resolves symbol dependencies during the compilation phase, allowing the current file to reference types, functions, macros, and variables defined outside its own module boundary.

Standard Import

The most common form of the declaration imports the entire public namespace of the target module.
import ModuleName

Access-Level Imports

Introduced in Swift 5.10, access-level modifiers control the transitive visibility of an imported module’s API to downstream clients. These modifiers replace legacy, unofficial attributes like @_exported and @_implementationOnly.
  • public import: Re-exports the imported module’s API, making its symbols available to any external client that imports the current module.
  • package import: Exposes the imported module’s API to other modules within the same Swift package boundary.
  • internal import: Restricts the imported module’s API to the current module. Symbols from the imported module cannot be exposed in the public API or ABI of the importing module.
  • private import: Restricts the imported module’s API strictly to the current source file.
public import ModuleA
package import ModuleB
internal import ModuleC
private import ModuleD

Symbol-Specific (Scoped) Import

To prevent namespace pollution or to resolve symbol collisions, Swift allows the importation of specific entities from a module. This restricts the imported scope to a single declaration. The syntax requires a declaration kind keyword followed by the fully qualified path to the symbol.
import <kind> ModuleName.SymbolName
Supported declaration kinds include class, struct, enum, protocol, typealias, func, let, var, and macro.
import class Foundation.RunLoop
import func Darwin.sin
import let Foundation.NSNotFound
import macro Observation.Observable

Submodule Import

When interacting with hierarchical modules (frequently encountered when bridging C or Objective-C libraries via module maps), Swift supports dot-notation to import specific submodules.
import ModuleName.SubmoduleName

Attributed Imports

Swift utilizes compiler attributes to modify the behavior, access control rules, and concurrency checking of the imported module.

@testable

Bypasses standard access control boundaries. When applied, symbols marked as internal within the target module become accessible to the importing file. The target module must be compiled with the ENABLE_TESTABILITY build setting.
@testable import ModuleName

@preconcurrency

Disables strict concurrency checking for symbols imported from a module that has not yet adopted Swift Concurrency. This attribute safely bridges legacy dependencies by suppressing Sendable and actor-isolation warnings that would otherwise occur when interacting with the unannotated module.
@preconcurrency import ModuleName

Namespace Disambiguation

When multiple imported modules contain identical symbols, Swift requires explicit module qualification to resolve the ambiguity. The module name acts as the top-level namespace.
import ModuleA
import ModuleB

// Resolving a collision where both modules define 'NetworkClient'
let clientA = ModuleA.NetworkClient()
let clientB = ModuleB.NetworkClient()
Master Swift with Deep Grasping Methodology!Learn More