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.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.
Standard Import
The most common form of the declaration imports the entire public namespace of the target module.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.
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.class, struct, enum, protocol, typealias, func, let, var, and macro.
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.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.
@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.
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.Master Swift with Deep Grasping Methodology!Learn More





