π¦ ClawHub
Swift
by @ivangdavila
Write safe Swift code avoiding memory leaks, optional traps, and concurrency bugs.
TERMINAL
clawhub install swiftπ About This Skill
name: Swift slug: swift version: 1.0.1 description: Write safe Swift code avoiding memory leaks, optional traps, and concurrency bugs. metadata: {"clawdbot":{"emoji":"π¦ ","requires":{"bins":["swift"]},"os":["darwin","linux"]}}
Quick Reference
| Topic | File |
|-------|------|
| Optionals, nil safety, force unwrap | optionals.md |
| Retain cycles, weak refs, closures | memory.md |
| async/await, actors, Sendable, value types | concurrency.md |
| JSON encoding/decoding traps | codable.md |
| Protocols, collections, strings, errors, build | types.md |
| SwiftUI state (@State, @Binding, Combine) | swiftui.md |
| Property wrappers, actors, result builders, macros | advanced.md |
| XCTest pitfalls, SPM gotchas | testing.md |
Critical Rules
Memory & Safety
! crashes on nil β use guard let or if let insteadself strongly create retain cycles β use [weak self] in escaping closuresweak β strong delegate = object never deallocatestry! crashes on any error β never use in production pathsremoveFirst() crashes on empty β use popFirst() for safetyConcurrency
async let starts immediately β not when you awaitawait β state may change between suspension points@MainActor doesn't guarantee immediate main thread β it's queuedSendable conformance violations crash at runtime β compiler warnings are errorsTypes & Collections
array[0].mutate() doesn't workString.Index from one string invalid on another β even if contents matchSwiftUI
@StateObject owns, @ObservedObject borrows β recreating view loses ObservedObject state@EnvironmentObject crashes if not injected β no compile-time check@State β changing ID loses stateBuild
print() builds strings even in release β remove or use os_log