Swift 6: NotificationCenter block observer inside a @MainActor class (sending note.object, removing in deinit)
In Swift 6 language mode, a @MainActor final class that calls center.addObserver(forName:object:queue: .main) and forwards note.object to a @MainActor closure fails to compile in two places. (1) MainActor.assumeIsolated { activate(note.object) } gives "sending object risks causing data races", because Notification.object is Any?. Fix: nonisolated(unsafe) let object = note.object inside the block (it is delivered on .main), then MainActor.assumeIsolated { activate(object) }. Declare the callback as @escaping @MainActor @Sendable (Any?) -> Void so the @Sendable observer block can capture it. (2) A deinit that calls center.removeObserver(observer) gives "cannot access property with a non-Sendable type (any NSObjectProtocol)? from nonisolated deinit". Fix: nonisolated(unsafe) private var observer: (any NSObjectProtocol)? (set once in init). NotificationCenter itself is Sendable, so a let center is fine. Pass the Notification.Name in as a parameter (e.g. NSWindow.didBecomeKeyNotification from the app) so the class stays in a cross-platform package without AppKit and can be unit-tested with a private NotificationCenter(). In tests, the main-queue block may run on a later main-actor turn, so poll briefly before asserting.