swiftlings-demo-for-git.mp4
Swiftlings is an interactive learning tool for Swift, inspired by Rustlings. It provides a structured path through Swift programming concepts. Each exercise is a small, focused problem designed to teach specific Swift features through hands-on practice.
This project is in very early development. While it has been tested and works well on macOS, it still requires proper testing and validation on Windows and Linux platforms.
brew tap tornikegomareli/swiftlings
brew install swiftlings
- Initialize a new Swiftlings project:
swiftlings init
This creates a new directory with all exercises.
- Navigate to the project directory:
cd swiftlings
- Start the interactive learning mode:
swiftlings
Interactive mode is default mode when u run
swiftlings
The default mode monitors your exercise files and automatically builds it and runs tests when you save changes.
While in watch mode, you can use these keyboard shortcuts:
n
- Move to next exerciseh
- Show hint for current exercisel
- List all exercisesq
- Quitr
- Re-run current exercisec
- Clear terminal
Run specific exercises directly:
swiftlings run variables1
List all exercises:
swiftlings list
Shows all exercises with their completion status and categories.
Get hints:
swiftlings hint variables1
Displays helpful hints for solving specific exercises.
Reset an exercise and its state:
swiftlings reset variables1
Restores an exercise to its original state.
Start the DSA learning mode to master data structures through implementation:
swiftlings dsa
Currently includes Queue exercises (6 progressive exercises building a FIFO data structure from scratch). New data structures and algorithms are coming soon!
I'm open to PRs for improving existing DSA exercises or adding new data structures and algorithms.
Exercises are organized into 19 progressive categories:
- 00_basics - Introduction and basic syntax
- 01_control_flow - if/else, switch, loops
- 02_functions - Function declaration and usage
- 03_collections - Arrays, sets, dictionaries
- 04_optionals - Swift's optional types
- 05_structs - Value types and structures
- 06_classes - Reference types and inheritance
- 07_enums - Enumerations and associated values
- 08_protocols - Protocol-oriented programming
- 09_extensions - Extending existing types
- 10_generics - Generic programming
- 11_error_handling - Error handling patterns
- 12_closures - Closures and functional programming
- 13_memory_management - ARC and memory management
- 14_property_wrappers - Property wrappers and observation
- 15_concurrency - Modern Swift concurrency
- 16_result_builders - DSL and result builders
- 17_advanced_types - Advanced type system features
- 18_codable - Encoding and decoding
Each exercise file contains:
- Instructions in comments explaining what to implement
- Code with
// TODO
markers indicating what needs to be fixed - Test cases that verify your solution
Your goal is to make all tests pass and solution to be compilable for each exercise. The CLI provides instant feedback as you work.
Swiftlings automatically tracks your progress through exercises. Your progress is saved locally and persists between sessions.
To update to the latest version:
brew update
brew upgrade swiftlings
git clone https://github.com/tornikegomareli/swiftlings.git
cd swiftlings
make build-release
make test
make format
I love contributions! Swiftlings is a community-driven project, and I welcome improvements from developers of all skill levels.
If you encounter an exercise that:
- Has incorrect test cases
- Contains compilation errors unrelated to the learning objective
- Has misleading or unclear instructions
Please open a PR with the fix! Even small corrections are valuable.
Learning is personal, and sometimes an exercise explanation doesn't click. If you can explain a concept more clearly:
- Fork the repository
- Improve the exercise comments and instructions
- Submit a PR with your improvements
I especially value contributions that make complex concepts more approachable for beginners.
The CLI itself is also open for improvements! If you encounter:
- Bugs in the watch mode, file detection, or command execution
- Issues with progress tracking or state management
- Problems with the build system or test runner
- Any crashes or unexpected behavior
- Performance issues or resource problems
Please report them or better yet, submit a fix! Technical contributions to the core tool are extremely valuable.
Got an idea for teaching a Swift concept better? I'd love to see it!
- Create a new Swift file in the appropriate category directory
- Add the exercise metadata to
exercises.json
- Include:
- Clear learning objectives
- Step-by-step instructions
- Helpful hints
- Test cases that guide learning
- Submit a pull request
- Found a typo?
- Have a clearer way to explain something?
- Want to add examples?
Documentation improvements are always welcome!
- Test Your Changes: Make sure all exercises compile and run correctly
- Follow Existing Patterns: Look at existing exercises for style and structure
- Keep It Focused: Each exercise should teach one concept clearly
- Be Encouraging: Write hints and messages that encourage learners
- Consider Difficulty: Place exercises appropriately in the progression
- Fork the repository
- Create a feature branch (
git checkout -b improve-optionals-exercise
) - Make your changes
- Test thoroughly (
make test
) - Commit with clear messages
- Push to your fork
- Open a PR with a description of what you changed and why
Not ready to fix it yourself? No problem! Open an issue describing:
- Which exercise has the problem (if exercise-related)
- What you expected to happen
- What actually happened
- Any error messages you saw
- Your environment (macOS version, Swift version, etc.)
Every contribution, no matter how small, helps make Swiftlings better for everyone learning Swift!
MIT License - see LICENSE file for details.
Inspired by Rustlings, the fantastic Rust learning tool.