summaryrefslogtreecommitdiff
path: root/DomainDig/SweepActivityController.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-07-22 21:43:42 -0500
committerChristian Cleberg <[email protected]>2026-07-22 23:23:11 -0500
commit872583eca8b4e7ae6ef85917604d4a5257b9d125 (patch)
tree0df88e0621e195f6adf5d0c67615f2099759a530 /DomainDig/SweepActivityController.swift
parentd3af0e7d51c2bac5de801bfbbed96a105c442e64 (diff)
downloaddomain-dig-872583eca8b4e7ae6ef85917604d4a5257b9d125.tar.gz
domain-dig-872583eca8b4e7ae6ef85917604d4a5257b9d125.tar.bz2
domain-dig-872583eca8b4e7ae6ef85917604d4a5257b9d125.zip
fix: adopt Swift 6 language mode; resolve all concurrency issues (#27)
All three product targets (app, widget, share extension) now build under SWIFT_VERSION = 6.0 with zero errors and zero warnings. The UITests target stays on 5.0: XCTestCase's nonisolated setUp/init overrides conflict with the target's MainActor default isolation under 6, and test tooling is not shipping code. The original seven diagnostics, plus the layers Swift 6 mode surfaced once those cleared: - SMTPChannel is an actor. It was implicitly MainActor while running its receive loop on a background queue, so parsedLines/lineWaiters/ receiveBuffer were declared main-actor-protected and mutated off it — concurrent mutation while resuming a CheckedContinuation can double-resume, which traps. The actor serialises all state; Network callbacks hop in via Task. The start() continuation also gains an OSAllocatedUnfairLock resume-once guard: the state handler can fire .ready and later .failed, and resuming twice was a pre-existing trap of the same family. - CachedLookupResult is nonisolated (a value pair built inside actor LookupRuntime cannot have a MainActor-bound memberwise init) with conditional Sendable — opting out of MainActor isolation also opted out of the implicit Sendable that globally-isolated types get. - PortScanService.printableBanner is nonisolated: a pure transformation called from the connection's queue. - SweepActivityController stores the activity's Sendable id instead of the non-Sendable Activity, re-resolving via Activity.activities inside each fire-and-forget task, so nothing non-Sendable crosses isolation. - App Intents' static title/description/openAppWhenRun become lets (get-only protocol requirements; static var is shared mutable global state), and the summary helpers are @MainActor to match the model properties they read and the perform() implementations that call them. - ExternalDataService's ISO8601DateFormatter is nonisolated(unsafe), citing Apple's documented thread-safety, rather than risking a parser behaviour change by switching APIs with no test coverage. - TaskMetricsDelegate.metrics is nonisolated(unsafe): written on the session's delegate queue, read only after the request completes, and URLSession guarantees didFinishCollecting precedes task completion. - The share extension extracts the host via async/withCheckedContinuation instead of sending a non-Sendable completion into loadItem's @Sendable handler; Task inherits the view controller's MainActor so the manual DispatchQueue.main hop goes too. Validated: clean Swift 6 build of all product targets, and the full enforced 11-test audit suite green on the floor runtime — Swift 6's runtime isolation checks ran the app through every screen without a trap.
Diffstat (limited to 'DomainDig/SweepActivityController.swift')
-rw-r--r--DomainDig/SweepActivityController.swift39
1 files changed, 27 insertions, 12 deletions
diff --git a/DomainDig/SweepActivityController.swift b/DomainDig/SweepActivityController.swift
index a00bb2f..e6d179e 100644
--- a/DomainDig/SweepActivityController.swift
+++ b/DomainDig/SweepActivityController.swift
@@ -2,11 +2,18 @@ import ActivityKit
import Foundation
/// Starts, updates, and ends the sweep Live Activity around a batch run.
+///
+/// Holds the activity's `id` (a Sendable `String`) rather than the
+/// `Activity` object itself. `Activity` is not Sendable, and sending the
+/// stored reference into the fire-and-forget update task while `self` still
+/// held it was a Swift 6 region-isolation violation (issue #27). Each task
+/// re-resolves the activity via `Activity.activities`, ActivityKit's
+/// sanctioned lookup, so nothing non-Sendable crosses an isolation boundary.
@MainActor
final class SweepActivityController {
static let shared = SweepActivityController()
- private var activity: Activity<SweepActivityAttributes>?
+ private var activityID: String?
private init() { /* Singleton; use the shared instance. */ }
@@ -23,14 +30,15 @@ final class SweepActivityController {
changed: 0,
warnings: 0
)
- activity = try? Activity.request(
+ let activity = try? Activity.request(
attributes: SweepActivityAttributes(title: title, startedAt: Date()),
content: ActivityContent(state: state, staleDate: nil)
)
+ activityID = activity?.id
}
func update(completed: Int, total: Int, currentDomain: String?) {
- guard let activity else { return }
+ guard let activityID else { return }
let state = SweepActivityAttributes.ContentState(
completed: completed,
total: total,
@@ -39,25 +47,32 @@ final class SweepActivityController {
warnings: 0
)
Task {
+ guard let activity = Self.activity(withID: activityID) else { return }
await activity.update(ActivityContent(state: state, staleDate: nil))
}
}
func end(changed: Int, warnings: Int, immediately: Bool = false) {
- guard let activity else { return }
- self.activity = nil
- let state = SweepActivityAttributes.ContentState(
- completed: activity.content.state.total,
- total: activity.content.state.total,
- currentDomain: nil,
- changed: changed,
- warnings: warnings
- )
+ guard let activityID else { return }
+ self.activityID = nil
Task {
+ guard let activity = Self.activity(withID: activityID) else { return }
+ let total = activity.content.state.total
+ let state = SweepActivityAttributes.ContentState(
+ completed: total,
+ total: total,
+ currentDomain: nil,
+ changed: changed,
+ warnings: warnings
+ )
await activity.end(
ActivityContent(state: state, staleDate: nil),
dismissalPolicy: immediately ? .immediate : .after(Date().addingTimeInterval(60))
)
}
}
+
+ private nonisolated static func activity(withID id: String) -> Activity<SweepActivityAttributes>? {
+ Activity<SweepActivityAttributes>.activities.first { $0.id == id }
+ }
}