Install any skill in seconds. Free to start, no credit card required.
Get Started Free →SwiftUI view composition, @Observable patterns, async/await concurrency, TCA architecture, and Combine reactive streams.
.claude/skills/swift-patterns/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-11 | ✗→✓ | ▲ Improved | — | — |
| case-03 | ✗→✓ | ▲ Improved | — | — |
| case-01 | ✗→✓ | ▲ Improved | — | — |
| case-10 | ✗→✓ | ▲ Improved | — | — |
| case-18 | ✓→✓ | = Same ✓ | — | — |
Modern Swift patterns for iOS/macOS application development.
swift// Small, focused views composed together struct ProductCard: View { let product: Product var body: some View { VStack(alignment: .leading, spacing: 8) { ProductImage(url: product.imageURL) ProductInfo(name: product.name, price: product.price) RatingStars(rating: product.rating, count: product.reviewCount) } .padding() .background(.regularMaterial) .clipShape(RoundedRectangle(cornerRadius: 12)) } } // Extract subviews for readability and reusability struct ProductImage: View { let url: URL var body: some View { AsyncImage(url: url) { phase in switch phase { case .success(let image): image.resizable().aspectRatio(contentMode: .fill) case .failure: Image(systemName: "photo").foregroundStyle(.secondary) case .empty: ProgressView() @unknown default: EmptyView() } } .frame(height: 200) .clipped() } } // ViewModifier for reusable styling struct CardModifier: ViewModifier { func body(content: Content) -> some View { content .padding() .background(.regularMaterial) .clipShape(RoundedRectangle(cornerRadius: 12)) .shadow(radius: 2) } } extension View { func cardStyle() -> some View { modifier(CardModifier()) } }
swiftimport Observation @Observable final class ProductStore { var products: [Product] = [] var isLoading = false var errorMessage: String? private let apiClient: APIClient init(apiClient: APIClient = .shared) { self.apiClient = apiClient } func loadProducts() async { isLoading = true errorMessage = nil do { products = try await apiClient.fetchProducts() } catch { errorMessage = error.localizedDescription } isLoading = false } func deleteProduct(_ product: Product) async throws { try await apiClient.deleteProduct(id: product.id) products.removeAll { $0.id == product.id } } } // Usage in SwiftUI (automatic tracking, no @Published needed) struct ProductListView: View { @State private var store = ProductStore() var body: some View { List(store.products) { product in ProductCard(product: product) } .overlay { if store.isLoading { ProgressView() } if let error = store.errorMessage { ContentUnavailableView("Error", systemImage: "exclamationmark.triangle", description: Text(error)) } } .task { await store.loadProducts() } } }
swift// TaskGroup for parallel async work func loadDashboard() async throws -> Dashboard { async let profile = apiClient.fetchProfile() async let orders = apiClient.fetchRecentOrders() async let recommendations = apiClient.fetchRecommendations() // All three run concurrently, await all results return try await Dashboard( profile: profile, orders: orders, recommendations: recommendations ) } // TaskGroup with dynamic number of tasks func loadImages(urls: [URL]) async -> [URL: UIImage] { await withTaskGroup(of: (URL, UIImage?).self) { group in for url in urls { group.addTask { let image = try? await ImageLoader.load(url) return (url, image) } } var results: [URL: UIImage] = [:] for await (url, image) in group { if let image { results[url] = image } } return results } } // Actor for thread-safe shared state actor ImageCache { private var cache: [URL: UIImage] = [:] private var inFlight: [URL: Task<UIImage, Error>] = [:] func image(for url: URL) async throws -> UIImage { if let cached = cache[url] { return cached } // Coalesce duplicate requests if let existing = inFlight[url] { return try await existing.value } let task = Task { let (data, _) = try await URLSession.shared.data(from: url) guard let image = UIImage(data: data) else { throw ImageError.invalidData } return image } inFlight[url] = task let image = try await task.value cache[url] = image inFlight[url] = nil return image } }
swiftimport ComposableArchitecture @Reducer struct ProductFeature { @ObservableState struct State: Equatable { var products: [Product] = [] var isLoading = false var alert: AlertState<Action>? } enum Action { case onAppear case productsLoaded(Result<[Product], Error>) case deleteProduct(Product) case alertDismissed } @Dependency(\.apiClient) var apiClient var body: some ReducerOf<Self> { Reduce { state, action in switch action { case .onAppear: state.isLoading = true return .run { send in let result = await Result { try await apiClient.fetchProducts() } await send(.productsLoaded(result)) } case .productsLoaded(.success(let products)): state.isLoading = false state.products = products return .none case .productsLoaded(.failure(let error)): state.isLoading = false state.alert = AlertState { TextState(error.localizedDescription) } return .none case .deleteProduct(let product): state.products.removeAll { $0.id == product.id } return .run { _ in try await apiClient.deleteProduct(id: product.id) } case .alertDismissed: state.alert = nil return .none } } } }
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +18 percentage points is the difference between those two pass rates over the 22 comparable cases.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.