Implement Swift 6 concurrency with async/await, actors, Sendable, Task, MainActor. Use when handling asynchronous operations, managing shared state safely, fixing data race errors, or migrating to Swift 6 strict concurrency.
/plugin marketplace add fusengine/claude-code-plugins/plugin install fuse:swift-apple-expert@fusengine-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
// Async function
func fetchUser(id: String) async throws -> User {
let (data, _) = try await URLSession.shared.data(from: url)
return try JSONDecoder().decode(User.self, from: data)
}
// Parallel execution
async let users = fetchUsers()
async let posts = fetchPosts()
let (loadedUsers, loadedPosts) = try await (users, posts)
// Task with cancellation
func loadData() {
task?.cancel()
task = Task {
try Task.checkCancellation()
let data = try await api.fetch()
guard !Task.isCancelled else { return }
await MainActor.run { self.items = data }
}
}
actor DataCache {
private var storage: [String: Data] = [:]
func get(_ key: String) -> Data? { storage[key] }
func set(_ key: String, data: Data) { storage[key] = data }
func clear() { storage.removeAll() }
}
// Usage - requires await
let cache = DataCache()
await cache.set("user", data: userData)
let data = await cache.get("user")
@MainActor
final class ViewModel: ObservableObject {
@Published var items: [Item] = []
@Published var isLoading = false
func refresh() async {
isLoading = true
defer { isLoading = false }
items = await repository.fetchItems()
}
}
// Or mark specific function
func updateUI() async {
await MainActor.run {
self.label.text = "Updated"
}
}
// Value types - automatic
struct User: Sendable {
let id: UUID
let name: String
}
// Reference types - must be immutable + final
final class Config: Sendable {
let apiKey: String
init(apiKey: String) { self.apiKey = apiKey }
}
// @unchecked when you manage safety manually
final class ThreadSafeCache: @unchecked Sendable {
private let lock = NSLock()
private var storage: [String: Any] = [:]
}
// Closures
func process(completion: @Sendable @escaping () -> Void) {
Task { completion() }
}
| Error | Solution |
|---|---|
| "not Sendable" | Make struct Sendable or use actor |
| "actor-isolated" | Add await or use nonisolated |
| "main actor-isolated" | Use @MainActor or MainActor.run |
| "capture of mutable" | Use let or capture in Task |
func fetchAllUsers(ids: [String]) async throws -> [User] {
try await withThrowingTaskGroup(of: User.self) { group in
for id in ids {
group.addTask { try await fetchUser(id: id) }
}
return try await group.reduce(into: []) { $0.append($1) }
}
}
This skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.