swift_structure

Swift language structures including collections, optionals, closures, generics, control flow, and core language features.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "swift_structure" with this command: npx skills add swiftzilla/skills/swiftzilla-skills-swift-structure

Swift Structure

This skill covers Swift's core language structures and features for building robust applications.

Overview

Swift structure skills cover the fundamental building blocks of the language: collections, optionals, control flow, closures, and other essential language features.

Available References

Collections

  • Array - Ordered collections, map/filter/reduce operations
  • Dictionary - Key-value pairs, lookups, transformations
  • Set - Unique elements, set algebra operations

Language Features

  • Optionals - Optional binding, unwrapping, nil handling
  • Closures - Closure expressions, trailing closure syntax
  • Generics - Generic types, constraints, associated types
  • Extensions - Type extensions, computed properties
  • Control Flow - Conditionals, loops, pattern matching
  • Error Handling - Throws, do-catch, Result type

Data Types

  • Strings - String manipulation, interpolation, Unicode

Quick Reference

Collections Comparison

CollectionOrderDuplicatesUse When
ArrayOrderedAllowedIndexed access needed
DictionaryUnorderedKeys uniqueKey-based lookup
SetUnorderedNot allowedUniqueness required

Optional Handling

// 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()

Common Higher-Order Functions

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

Best Practices

  1. Use appropriate collection - Match collection to use case
  2. Handle optionals safely - Never force unwrap without certainty
  3. Leverage higher-order functions - Cleaner functional code
  4. Use extensions for organization - Group related functionality
  5. Prefer generics for reusability - Type-safe flexible code
  6. Make switch exhaustive - Handle all cases
  7. Use do-catch properly - Handle errors appropriately

For More Information

Each reference file contains detailed information, code examples, and best practices for specific topics. Visit https://swiftzilla.dev for comprehensive Swift documentation.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

swift_swiftui

No summary provided by upstream source.

Repository SourceNeeds Review
General

swift_concurrency

No summary provided by upstream source.

Repository SourceNeeds Review
General

swift_style

No summary provided by upstream source.

Repository SourceNeeds Review
General

swift_combine

No summary provided by upstream source.

Repository SourceNeeds Review