| name | Actor Isolation Fixer |
| description | Fix Swift 6 actor isolation errors in Leavn app - deinit accessing @MainActor properties, nonisolated contexts, concurrent access violations |
| allowed-tools | Read, Edit, Grep |
Actor Isolation Fixer
Instructions
Fix actor isolation errors systematically:
-
Error: "main actor-isolated property X cannot be accessed from nonisolated"
- In deinit: Mark property as
nonisolated(unsafe) private var
- In closure: Add
@MainActor to Task or use await MainActor.run { }
- In method: Mark method
@MainActor or nonisolated
-
Common Leavn patterns:
nonisolated(unsafe) private var timer: Timer?
deinit {
timer?.invalidate()
}
nonisolated(unsafe) private var task: Task<Void, Never>?
deinit {
task?.cancel()
}
-
Don't use nonisolated(unsafe) for:
- UI properties (views, layers)
- Mutable state accessed across threads
- Non-thread-safe types
-
Safe to use nonisolated(unsafe) for:
- Timers (invalidate is thread-safe)
- Tasks (cancel is thread-safe)
- Notification observers (removeObserver is thread-safe)
Use this skill when: Actor isolation errors, deinit cannot access properties, concurrent access violations