Use Swift 6.4 Diagnostics To Make A Migration Manageable

You want the build to reject new uses of a deprecated API. One compatibility adapter still has to read documents written by the previous app version. Turning off the rule for the whole target would let that dependency spread again.

Swift 6.4, released September 15, adds source-level warning control through @diagnose. It gives this migration a more useful shape: a strict default with a small exception beside the code that needs it.

Start with a reproducible warning

The following fixture stands in for an old document reader:

@available(*, deprecated, message: "Use readCurrentFormat()")
func readLegacyFormat() -> Int { 1 }

@diagnose(
    DeprecatedDeclaration, as: warning,
    reason: "Read v1 documents until their on-disk migration is complete")
func decodeVersionOneDocument() -> Int {
    readLegacyFormat()
}

The stub returns an integer because this example is about compiler behavior, not document decoding. In a real app, the adapter would convert the old representation into the current model at a well-defined boundary.

Compile it with a target-wide policy that promotes this diagnostic group:

xcrun swiftc -swift-version 6 -typecheck \
  -Werror DeprecatedDeclaration DiagnosticScope.swift

With the Swift 6.4 toolchain used for this post, the call inside decodeVersionOneDocument remains a warning and compilation succeeds. The warning is still visible in the build log. The reason records why this particular declaration needs different treatment.

SE-0522 defines the attribute, its lexical scope, and the warning, error, and ignored behaviors. Keep the annotation as narrow as the compatibility requirement allows.

Prove the surrounding policy still works

Now add an unrelated caller outside the annotated function:

func newFeature() -> Int {
    readLegacyFormat()
}

Compile with the same command. This time the new caller produces an error and the command fails. That negative check matters: a successful compatibility build alone does not prove the rest of the target remains strict.

I would keep these two outcomes in a tiny migration fixture. The intended adapter may compile with its visible warning; an unapproved new call must fail. If a build-setting change makes both pass, the migration boundary has weakened even though the main app may still build.

Use the diagnostic group emitted by your actual compiler. In this fixture, the diagnostic includes DeprecatedDeclaration. Do not guess a group from the warning’s English sentence, and do not assume every diagnostic is a configurable warning.

Make the reason actionable

“Temporary workaround” tends to survive forever. A useful reason identifies the compatibility condition: the v1 file reader remains until existing documents have a supported migration path. Track the work that will remove the adapter, and give it an owner.

Review new annotations like changes to build policy. A method-level exception for a legacy decoder is easy to inspect. An annotation on a large application type can quietly cover new code added months later.

Prefer leaving the diagnostic visible when the team still needs to track the debt. An ignored warning may be appropriate for a carefully understood boundary, but it removes a useful reminder. The code review should explain why visibility itself is a problem before choosing that behavior.

Separate warning policy from correctness

This attribute changes diagnostics. It does not make an unavailable API callable, serialize a data race, or make an unsafe lifetime valid. Fix correctness errors through the model and API design that caused them.

Likewise, a compiler upgrade, a Swift language-mode migration, and a deployment-target change are different decisions. This example requires a compiler that understands the Swift 6.4 attribute. Adding a diagnostic annotation is not a reason to raise the app’s minimum iOS version or change its marketing version.

If an older toolchain still builds the project, plan source compatibility explicitly before adding new syntax. Check both the developer toolchain and CI’s selected Xcode, rather than relying on the version installed on one machine.

Remove the exception when the boundary disappears

Once the old reader is no longer required, remove the adapter and its annotation together. Run the negative check again to make sure the strict target policy still catches accidental reintroduction.

September 2026 verification: both compiler outcomes were reproduced with Apple Swift 6.4 in Xcode 27.0: the annotated compatibility call warned and returned exit status zero; the unrelated deprecated call produced an error and a nonzero exit status.

The practical benefit is a migration you can finish in pieces while preserving a clear direction. New code follows the rule, old-format support stays explicit, and the exception has a concrete reason to disappear.