Resolve Name Collisions With Swift Module Selectors
Two packages both add recordKey() to String. Your app imports both, and a previously obvious call becomes ambiguous. Qualifying the String type does not identify which package’s extension you meant.
Swift’s module selectors give that call an explicit owner. They are highlighted in the Swift 6.4 release overview, and the examples below are checked with that compiler. The SE-0491 proposal currently records implementation in Swift 6.3, so this is not a claim that the syntax first became possible on September 15.
Reproduce the collision with two tiny modules
Imagine a storage package named ArchiveKit. It declares both a type with the module’s name and a Record type:
// ArchiveKit.swift, compiled as module ArchiveKit
public struct ArchiveKit { public init() {} }
public struct Record { public init() {} }
extension String {
public func recordKey() -> String { "archive:" + self }
}
A search package supplies another Record and another extension with the same spelling:
// SearchKit.swift, compiled as module SearchKit
public struct Record { public init() {} }
extension String {
public func recordKey() -> String { "search:" + self }
}
These methods intentionally have different semantics. Picking one changes the generated key. The example is about controlling name lookup, not recommending globally common extension names for package APIs.
Select the module before the declaration
The client can identify each Record without depending on which other names happen to be visible:
import ArchiveKit
import SearchKit
let stored: ArchiveKit::Record = .init()
let found: SearchKit::Record = .init()
The double colon identifies the module. In this fixture, ordinary ArchiveKit.Record() fails because the name ArchiveKit resolves to the struct, which has no nested Record type. That is the useful difference from familiar dot qualification: the module selector does not ask the compiler to guess whether this spelling refers to a module or a type.
You still import the dependency. A selector is not a package declaration, a linker directive, or a way around access control. If Record is internal to another module, adding punctuation does not make it public.
Select the extension that defines the member
For the String extension, put the selector at the member lookup:
let archiveKey = "draft".ArchiveKit::recordKey()
let searchKey = "draft".SearchKit::recordKey()
precondition(archiveKey == "archive:draft")
precondition(searchKey == "search:draft")
This makes the behavioral dependency visible right where it matters. The unqualified "draft".recordKey() is ambiguous while both extensions are imported.
A useful application is a small integration adapter. Keep the explicit selection beside the boundary where storage and search packages meet, and expose a domain-specific operation such as makeStorageKey to the rest of the app. That avoids spreading package-specific details through every view model.
Do not use selectors to conceal a genuinely confusing API you own. If two internal helpers do different things, better names may still be the clearest fix. Explicit module selection is particularly useful when dependencies or generated code constrain the names available to you.
Test the error you are fixing
The companion fixture builds two real modules, links a client, and checks both returned strings. It also runs two negative compiler checks: the unqualified extension call must fail as ambiguous, and the dotted ArchiveKit.Record() expression must fail because the struct shadows the module.
Those negative cases establish why the new syntax is doing useful work. A client that merely compiles does not show whether the intended collision existed in the first place.
Keep the compiler version in the fixture’s output or build record. This is a source-language feature. An iOS runtime availability check cannot make an older compiler parse syntax it does not understand. Verify the oldest supported developer and CI toolchains before adopting it in shared source.
Keep the change local
A focused migration should not rename both packages, rewrite all imports, or change the app’s deployment target. Start with the conflicting call, explicitly select the declaration, and run the behavior test that depends on its result.
September 2026 verification: Apple Swift 6.4 compiled and linked the two modules and client. Both selected extension results passed runtime assertions. The ambiguous member call and shadowed dotted type lookup each produced the expected nonzero compiler result. No experimental compiler flag was needed.