Swift Concurrency
ASecurityAnnotate UI types or members with `@MainActor`: ```swift @MainActor final class ProfileViewModel: ObservableObject { @Published var name = "" func load() async { let profile = await fetchProfile() name = profile.name } nonisolated func makeRequestID() -> UUID { UUID() } } ``` For SwiftUI views: ```swift @MainActor struct ProfileView: View { @StateObject private var viewModel = ProfileViewModel() var body: some View { Text(viewModel.name) .task { await viewModel.load() } } } ``` Use `@MainActo...
- 584 stars
- 0 votes
- 0 copies
- 2 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 16 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill swift-concurrency --agent claude-codeAre you the author of Swift Concurrency?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-swift-concurrency-6bc75c8c)Annotate UI types or members with `@MainActor`:
```swift
@MainActor
final class ProfileViewModel: ObservableObject {
@Published var name = ""
func load() async {
let profile = await fetchProfile()
name = profile.name
}
nonisolated func makeRequestID() -> UUID {
UUID()
}
}
```
For SwiftUI views:
```swift
@MainActor
struct ProfileView: View {
@StateObject private var viewModel = ProfileViewModel()
var body: some View {
Text(viewModel.name)
.task {
await viewModel.load()
}
}
}
```
Use `@MainActor` on individual properties or methods when only part of a type updates UI:
```swift
final class Controller {
@MainActor var title = ""
@MainActor
func updateTitle(_ value: String) {
title = value
}
}
```
From an async context that is not main-actor isolated, use:
```swift
await MainActor.run {
viewModel.name = "Updated"
}
```
`Task { ... }` inherits the surrounding actor isolation, so a task created from `@MainActor` UI code remains main-actor isolated. Avoid `Task.detached` for UI work. Mark methods `nonisolated` only when they do not access actor-isolated state.
Keep synchronous work inside `@MainActor` short; never block the main thread. UI updates must not occur off `@MainActor`. Use `async`/`await` for asynchronous work and check or propagate cancellation in long-running tasks.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- eval-4.baseline.md
- eval-4.with-skill.md
- eval-5.baseline.md
- eval-5.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.