Missing module for canImport (CanImportMissingModule)
Warnings that indicate a versioned #if canImport(<ModuleName>, _version: <version>) or #if canImport(<ModuleName>, _underlyingVersion: <version>) directive could not find the named module.
Overview
Developers may use a versioned #if canImport directive to conditionally compile code based on the version of a dependency module:
#if canImport(Dependency, _version: 1.2)
// Use declarations introduced in version 1.2 of Dependency
#endifA versioned canImport check evaluates to false if the named module cannot be resolved. The compiler emits a warning in case this case:
warning: cannot find module 'Dependency' for canImport check; the directive will evaluate to false [#CanImportMissingModule]If the module is expected to be missing in some configurations, you can suppress the warning by checking whether the module can be imported at all before checking its version:
#if canImport(Dependency) && canImport(Dependency, _version: 1.2)
// ...
#endifSee Also
@dynamicCallable implementation requirements (DynamicCallable)Add @preconcurrency import (AddPreconcurrencyImport)Always enabled availability domains (AlwaysAvailableDomain)Argument matching for trailing closures (TrailingClosureMatching)Calling a mutating async actor-isolated method (ActorIsolatedMutatingAsync)Calling an actor-isolated method from a synchronous nonisolated context (ActorIsolatedCall)Captures in a `@Sendable` closure (SendableClosureCaptures)Compilation caching (CompilationCaching)Conforming to `StringInterpolationProtocol` (StringInterpolationConformance)Conversion from `@isolated(any)` function type to synchronous function type (ConversionFromIsolatedAnyToSynchronous)Cross-isolation data race (RegionIsolationCrossIsolationDataRace)Deprecated declaration warnings (DeprecatedDeclaration)Deprecated implementation-only imports (ImplementationOnlyDeprecated)Dynamic exclusivity (DynamicExclusivity)Embedded Swift language restrictions (EmbeddedRestrictions)