English | 简体中文
Hello Swift Tutorial | GitHub Pages
A comprehensive sample project and tutorial for learning the Swift programming language, from basic syntax to advanced production-grade applications.
- 🌐 Official Tutorial: renyan.org/hello/swift
- 📚 GitHub Pages: savechina.github.io/hello-swift
# Clone the project
git clone https://github.com/savechina/hello-swift.git
cd hello-swift
# Build and run
swift run hello --help
# Run specific sample modules
swift run hello basic # Basic Swift samples
swift run hello advance # Advanced samples
swift run hello awesome # Awesome samples
swift run hello algo # Algorithm samples
# Run tests
swift testCore Swift syntax and concepts for beginners:
| Module | Content |
|---|---|
| Variables & Expressions | Variable binding, mutability, operators, string interpolation |
| Control Flow | if/else, switch/case, for-in loops, range iteration |
| Data Types | Integers, floats, booleans, strings, arrays, sets, dictionaries |
| Functions | Function declaration, tuples, variadic parameters, nested functions, closures |
| Enums | Enum definitions, associated values, raw values, pattern matching |
| Structs & Classes | Struct/value types, class/reference types, inheritance, computed properties, subscripts |
| Protocols | Protocol definitions, class/struct extensions, protocol-oriented programming |
| Access Control | public, internal, fileprivate, private, open, extension visibility |
| Generics | Generic functions and types |
| Error Handling | Error types, do/catch/try patterns |
| Concurrency | async/await, actors, AsyncStream, withTaskGroup, Thread + semaphores |
| Date/Time & UUID | ContinuousClock, Date formatting, UUID v3/v4/v7 |
| Logging | os.Logger, swift-log, SwiftyBeaver integration |
| Module System | Extension-based namespace pattern (MyModule) |
Deep dive into advanced Swift features and ecosystem:
| Module | Content |
|---|---|
| JSON Processing | JSONSerialization, JSONDecoder/Encoder, SwiftyJSON |
| File Operations | FileManager, temporary files, directory traversal |
| System Services | SystemConfiguration, network reachability, metrics |
| Async Programming | Task, async/await with SwiftNIO |
| Environment Config | swift-dotenv, .env file integration |
| Module | Content |
|---|---|
| Algorithms | Two Sum, Pi calculation (BigNum precision) |
| LeetCode Solutions | LeetCode problem implementations |
| Awesome Examples | Third-party library integrations and tool demos |
- Swift 6.0
- CLI: swift-argument-parser
- Algorithms: swift-algorithms, swift-numerics, swift-bignum
- Logging: swift-log, SwiftyBeaver
- Collections: swift-collections
- JSON/Data: SwiftyJSON
- Networking/Async: swift-nio
- Config: swift-dotenv
hello-swift/
├── Sources/
│ ├── HelloSample/ # @main CLI entry point (ArgumentParser)
│ ├── BasicSample/ # Core Swift fundamentals (12 files)
│ │ └── ModuleSample/ # Namespace pattern demo
│ └── AlgoSample/ # Algorithm implementations
├── Tests/
│ ├── HelloSampleTests/ # Integration tests
│ └── AlgoSampleTests/ # Algorithm tests
├── AdvanceSample/ # Nested SPM package (SwiftyJSON, swift-nio, dotenv)
├── AwesomeSample/ # Nested SPM package (third-party integrations)
├── LeetCodeSample/ # Nested SPM package (LeetCode solutions)
├── Docs/ # mdBook tutorial documentation (Chinese)
├── Config/ # Test resources
MIT License