Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

swift

/swift

Wspiera pracę ze Swiftem 6: strict concurrency, async/await, actors, protokoły, generyki, zarządzanie pamięcią z ARC i integracja z SwiftUI przy aplikacjach iOS i macOS.

Repozytorium
Agent-Skills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
01.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
3
Przestarzałość

Brak sygnałów. Repozytorium zmienione 01.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Wspiera pracę ze Swiftem 6: strict concurrency, async/await, actors, protokoły, generyki, zarządzanie pamięcią z ARC i integracja z SwiftUI przy aplikacjach iOS i macOS.

Oryginalny opis (EN)

Expert Swift assistance covering Swift 6 strict concurrency, async/await, actors, protocols, generics, memory management with ARC, and SwiftUI integration. Use when writing iOS/macOS applications, debugging concurrency warnings, or building robust Swift codebases.

Jak działa

  1. When to Use
  2. Quick Start
  3. Core Concepts
  4. Common Patterns
  5. Best Practices
  6. Troubleshooting
  7. References
Sekcje z nagłówków SKILL.md, w oryginale · 206 linii, 741 słów
Podgląd SKILL.md
---
name: swift
description: Expert Swift assistance covering Swift 6 strict concurrency, async/await, actors, protocols, generics, memory management with ARC, and SwiftUI integration. Use when writing iOS/macOS applications, debugging concurrency warnings, or building robust Swift codebases.
---

# Swift

Modern Swift development with protocol-oriented programming and async/await.

## When to Use

- **Apple Ecosystem Native Applications**: iOS, iPadOS, macOS, watchOS, and visionOS applications using SwiftUI.
- **Modern Concurrent Systems**: Utilizing Swift 6 complete concurrency checking, actors, and structured `Task` trees.
- **Cross-Platform Server-Side Swift**: High-performance backends and microservices built with Hummingbird or Vapor.
- **Embedded & Real-Time Edge Processing**: Utilizing Embedded Swift for microcontrollers and real-time audio engines.

## Quick Start

```swift
struct User: Identifiable, Codable {
    let id: UUID
    var name: String
    var email: String

    var displayName: String {
        name.capitalized
    }
}
```

## Core Concepts

### Modern Swift 6 Concurrency: Actors & Structured Tasks

Data-race safety guaranteed at compile time with Sendable enforcement and actors:

```swift
import Foundation

// Thread-safe state isolation via actor
actor AccountManager {
    private var balances: [UUID: Decimal] = [:]

    func deposit(to accountId: UUID, amount: Decimal) {
        guard amount > 0 else { return }
        balances[accountId, default: 0] += amount
    }

    func balance(for accountId: UUID) -> Decimal {
        balances[accountId, default: 0]
    }
}

// Structured concurrency with TaskGroup
func fetchUserMetrics(userIds: [UUID]) async throws -> [UUID: Decimal] {
    let manager = AccountManager()

    return try await withThrowingTaskGroup(of: (UUID, Decimal).self) { group in
        for id in userIds {
            group.addTask {
                let bal = await manager.balance(for: id)
                return (id, bal)
            }
        }

        var results: [UUID: Decimal] = [:]
        for try await (id, bal) in group {
            results[id] = bal
        }
        return results
    }
}
```

### Protocol-Oriented Architecture & Primary Associated Types

Expressive type contracts using Swift 5.7+ `some` and `any` semantics:

```swift
// Protocol with primary associated type
protocol Repository<Entity>: Sendable {
    associatedtype Entity: Identifiable, Sendable
    func fetch(by id: Entity.ID) async throws -> Entity?
    func save(_ entity: Entity) async throws
}

struct User: Identifiable, Sendable {
    let id: UUID
    let name: String
}

final class InMemoryUserRepository: Repository {
    private var store: [UUID: User] = [:]

    func fetch(by id: UUID) async throws -> User? {
        store[id]
    }

    func save(_ entity: User) async throws {
        store[entity.id] = entity
    }
}

// Opaque return type using 'some' for static dispatch performance
func makeDefaultRepo() -> some Repository<User> {
    InMemoryUserRepository()
}
```

### Result Builders & Custom DSLs

Constructing declarative hierarchies modeled after SwiftUI:

```swift
@resultBuilder
struct HTMLBuilder {
    static func buildBlock(_ components: String...) -> String {
        components.joined(separator: "
")
    }

    static func buildOptional(_ component: String?) -> String {
        component ?? ""
    }
}

func htmlDoc(@HTMLBuilder content: () -> String) -> String {
    "<html>
<body>
\(content())
</body>
</html>"
}

let page = htmlDoc {
    "<h1>Welcome to Swift 6</h1>"
    "<p>Safe, fast, and expressive systems programming.</p>"
}
```

## Common Patterns

### Modern Async/Await Network Request

**Problem**: Deeply nested completion handler callbacks and error propagation bugs in asynchronous code.

**Solution**:

```swift
func fetchUser(id: UUID) async throws -> User {
    let url = URL(string: "https://api.example.com/users/\(id)")!
    let (data, response) = try await URLSession.shared.data(from: url)

    guard let httpResponse = response as? HTTPURLResponse,
          httpResponse.statusCode == 200 else {
        throw NetworkError.invalidResponse
    }

    return try JSONDecoder().decode(User.self, from: data)
}

// Parallel execution
async let user = fetchUser(id: userId)
async let orders = fetchOrders(userId: userId)
let (userResult, ordersResult) = try await (user, orders)
```

### Actors

**Problem**: Preventing concurrent data race bugs when mutating shared mutable state across asynchronous tasks.

**Solution**:

```swift
actor UserCache {
    private var cache: [UUID: User] = [:]

    func get(_ id: UUID) -> User? { cache[id] }
    func set(_ user: User) { cache[user.id] = user }
}
```

## Best Practices

**Do**:

- Enable Swift 6 complete concurrency checking (`-strict-concurrency=complete`) to catch data races at compile time.
- Prefer `struct` and value types over `class` unless reference identity or Objective-C runtime bridging is explicitly required.
- Favor `some Protocol` (opaque types) over `any Protocol` (existential types) to eliminate dynamic dispatch overhead.
- Use `async/await` and structured `withTaskGroup` rather than legacy completion handlers and Grand Central Dispatch (`DispatchQueue`).

**Don't**:

- Force unwrap optionals (`!`) in production; use `guard let`, `if let`, or default coalescing (`??`).
- Capture strong `self` references in escaping closures; use `[weak self]` to avoid retain cycles.
- Bypass actor isolation with `@unchecked Sendable` without verifying thread-safety invariants.

## Troubleshooting

| Error                     | Cause                                | Solution             |
| ------------------------- | ------------------------------------ | -------------------- |
| `unexpectedly found nil`  | Force unwrap of nil                  | Use optional binding |
| `Actor-isolated property` | Accessing actor from sync context    | Use `await`          |
| `Sendable closure`        | Non-sendable type across concurrency | Make type Sendable   |

## References

- [Swift.org Documentation](https://swift.org/documentation/)
- [Hacking with Swift](https://www.hackingwithswift.com/)

Wersje

RepozytoriumWynikLicencja
Ta strona · G1Joshi/Agent-Skills100MIT
nimadorostkar/Claude-Skills-collection100MIT
appwrite/claude-plugin95BSD-3-Clause
claude-dev-suite/claude-dev-suite95MIT
clawic/skills90MIT
maragudk/fabrik86MIT
dkbnull/hello-skill86MIT

Migawka bazy z 13.11.2026 · wersja paczki ad05913c22b0 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100swift-concurrency
    Wdraża async/await, Actors i structured concurrency w Swifcie dla aplikacji iOS i macOS.
  • 90ios-swift-concurrency
    Pomaga wdrażać async/await, zarządzanie Task, aktorów i wzorce reaktywne Combine w aplikacjach iOS.
  • 100swift-expert
    Buduje aplikacje iOS, macOS, watchOS i tvOS w Swift: widoki SwiftUI, zarządzanie stanem, architekturę protokołów i błędy specyficzne dla Swift.
  • 100swift-expert
    Buduje aplikacje na iOS, macOS, watchOS i tvOS: widoki i stan w SwiftUI, architektura protokołowa, async/await, actors i debugowanie problemów specyficznych dla Swifta.
  • 100swift-expert
    Buduje natywne aplikacje iOS, macOS i serwerowe w Swift, z wzorcami async i aktorów, architekturą protokołową i modernizacją SwiftUI.
  • 90neo-swift
    Pomaga pisać, recenzować, debugować i modernizować kod Swift dla iOS, macOS i Swift po stronie serwera: współbieżność strukturalna, bezpieczeństwo pamięci, protokoły, generyki i wydajność.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.