Section 13/171 menit
13. Migrasi Strict Concurrency Checking
13. Migrasi Strict Concurrency Checking
Fase 1: Aktifkan Warning Mode
Di SPM:
swift
// Package.swift
.target(
name: "MyLib",
swiftSettings: [
.enableUpcomingFeature("StrictConcurrency"),
.enableUpcomingFeature("InferSendableFromCaptures"),
]
)
Di Xcode project: Build Settings → Swift Strict Concurrency Checking → Complete.
Fase 2: Triage Warning
Kategorikan warning:
| Warning | Strategi |
|---|---|
| "X is not Sendable" untuk model | Tambah : Sendable |
| "Capture of X in @Sendable closure" | let snapshot atau actor isolation |
| "Cross-actor reference" | Tambah await, isolasi method dengan tepat |
| "Stored property in actor is mutable" | OK kalau private, refactor kalau public |
Fase 3: Refactor Bertahap per Module
Aktifkan strict di module dependency lebih dulu (core, utility), lalu naik ke app shell.
swift
Core → Networking → Repository → Service → ViewModel → App
Fase 4: Hapus @preconcurrency Bertahap
@preconcurrency adalah suppresor warning sementara untuk import API legacy. Saat upstream sudah Sendable-ready, hapus.
swift
// Sementara
@preconcurrency import OldFramework
// Setelah upstream di-update
import OldFramework
Fase 5: Strict di CI
Setelah project bersih, jadikan strict checking sebagai CI gate.
swift
# CI: kalau build menghasilkan warning concurrency, fail
- run: swift build -Xswiftc -warnings-as-errors