Loading...
Loading...
Swift language structures including collections, optionals, closures, generics, control flow, and core language features.
npx skill4agent add swiftzilla/skills swift_structure| Collection | Order | Duplicates | Use When |
|---|---|---|---|
| Array | Ordered | Allowed | Indexed access needed |
| Dictionary | Unordered | Keys unique | Key-based lookup |
| Set | Unordered | Not allowed | Uniqueness required |
// Optional binding
if let value = optional { }
guard let value = optional else { return }
// Nil coalescing
let value = optional ?? defaultValue
// Optional chaining
let result = object?.property?.method()array.map { $0 * 2 } // Transform
array.filter { $0 > 0 } // Select
array.reduce(0, +) // Combine
array.compactMap { Int($0) } // Transform + remove nil
array.flatMap { $0 } // Flatten