|
| 1 | +## Overview 🦉 |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +### ⚠️ Early Development Notice |
| 6 | + |
| 7 | +**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. Features may change, and you might encounter bugs. Please report any issues you find! |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +### Install via Homebrew |
| 12 | + |
| 13 | +```bash |
| 14 | +brew tap tornikegomareli/swiftlings |
| 15 | +brew install swiftlings |
| 16 | +``` |
| 17 | + |
| 18 | +## Getting Started |
| 19 | + |
| 20 | +1. Initialize a new Swiftlings project: |
| 21 | + |
| 22 | +```bash |
| 23 | +swiftlings init |
| 24 | +``` |
| 25 | + |
| 26 | +This creates a new directory with all exercises. |
| 27 | + |
| 28 | +2. Navigate to the project directory: |
| 29 | + |
| 30 | +```bash |
| 31 | +cd swiftlings |
| 32 | +``` |
| 33 | + |
| 34 | +3. Start the interactive learning mode: |
| 35 | + |
| 36 | +```bash |
| 37 | +swiftlings |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +### Interactive Mode |
| 43 | + |
| 44 | +Interactive mode is default mode when u run |
| 45 | + |
| 46 | +```bash |
| 47 | +swiftlings |
| 48 | +``` |
| 49 | + |
| 50 | +The default mode monitors your exercise files and automatically builds it and runs tests when you save changes. |
| 51 | + |
| 52 | +#### Interactive Commands |
| 53 | + |
| 54 | +While in watch mode, you can use these keyboard shortcuts: |
| 55 | + |
| 56 | +- `n` - Move to next exercise |
| 57 | +- `h` - Show hint for current exercise |
| 58 | +- `l` - List all exercises |
| 59 | +- `q` - Quit |
| 60 | +- `r` - Re-run current exercise |
| 61 | +- `c` - Clear terminal |
| 62 | + |
| 63 | +### Manual Mode |
| 64 | + |
| 65 | +Run specific exercises directly: |
| 66 | + |
| 67 | +```bash |
| 68 | +swiftlings run variables1 |
| 69 | +``` |
| 70 | + |
| 71 | +### Other Commands |
| 72 | + |
| 73 | +**List all exercises:** |
| 74 | +```bash |
| 75 | +swiftlings list |
| 76 | +``` |
| 77 | + |
| 78 | +Shows all exercises with their completion status and categories. |
| 79 | + |
| 80 | +**Get hints:** |
| 81 | +```bash |
| 82 | +swiftlings hint variables1 |
| 83 | +``` |
| 84 | + |
| 85 | +Displays helpful hints for solving specific exercises. |
| 86 | + |
| 87 | +**Reset an exercise and its state:** |
| 88 | +```bash |
| 89 | +swiftlings reset variables1 |
| 90 | +``` |
| 91 | + |
| 92 | +Restores an exercise to its original state. |
| 93 | + |
| 94 | +## Exercise Structure |
| 95 | + |
| 96 | +Exercises are organized into 19 progressive categories: |
| 97 | + |
| 98 | +1. **00_basics** - Introduction and basic syntax |
| 99 | +2. **01_control_flow** - if/else, switch, loops |
| 100 | +3. **02_functions** - Function declaration and usage |
| 101 | +4. **03_collections** - Arrays, sets, dictionaries |
| 102 | +5. **04_optionals** - Swift's optional types |
| 103 | +6. **05_structs** - Value types and structures |
| 104 | +7. **06_classes** - Reference types and inheritance |
| 105 | +8. **07_enums** - Enumerations and associated values |
| 106 | +9. **08_protocols** - Protocol-oriented programming |
| 107 | +10. **09_extensions** - Extending existing types |
| 108 | +11. **10_generics** - Generic programming |
| 109 | +12. **11_error_handling** - Error handling patterns |
| 110 | +13. **12_closures** - Closures and functional programming |
| 111 | +14. **13_memory_management** - ARC and memory management |
| 112 | +15. **14_property_wrappers** - Property wrappers and observation |
| 113 | +16. **15_concurrency** - Modern Swift concurrency |
| 114 | +17. **16_result_builders** - DSL and result builders |
| 115 | +18. **17_advanced_types** - Advanced type system features |
| 116 | +19. **18_codable** - Encoding and decoding |
| 117 | + |
| 118 | +## How It Works |
| 119 | + |
| 120 | +Each exercise file contains: |
| 121 | + |
| 122 | +- Instructions in comments explaining what to implement |
| 123 | +- Code with `// TODO` markers indicating what needs to be fixed |
| 124 | +- Test cases that verify your solution |
| 125 | + |
| 126 | +Your goal is to make all tests pass and solution to be compilable for each exercise. The CLI provides instant feedback as you work. |
| 127 | + |
| 128 | +## Progress Tracking |
| 129 | + |
| 130 | +Swiftlings automatically tracks your progress through exercises. Your progress is saved locally and persists between sessions. |
| 131 | + |
| 132 | +## Updating |
| 133 | + |
| 134 | +To update to the latest version: |
| 135 | + |
| 136 | +```bash |
| 137 | +brew update |
| 138 | +brew upgrade swiftlings |
| 139 | +``` |
| 140 | + |
| 141 | +## Development |
| 142 | + |
| 143 | +### Building from Source |
| 144 | + |
| 145 | +```bash |
| 146 | +git clone https://github.com/tornikegomareli/swiftlings.git |
| 147 | +cd swiftlings |
| 148 | +make build-release |
| 149 | +``` |
| 150 | + |
| 151 | +### Running Tests |
| 152 | + |
| 153 | +```bash |
| 154 | +make test |
| 155 | +``` |
| 156 | + |
| 157 | +### Code Formatting |
| 158 | + |
| 159 | +```bash |
| 160 | +make format |
| 161 | +``` |
| 162 | + |
| 163 | +## Contributing |
| 164 | + |
| 165 | +I love contributions! Swiftlings is a community-driven project, and I welcome improvements from developers of all skill levels. |
| 166 | + |
| 167 | +### Ways to Contribute |
| 168 | + |
| 169 | +#### Found a Bug in an Exercise? |
| 170 | + |
| 171 | +If you encounter an exercise that: |
| 172 | +- Has incorrect test cases |
| 173 | +- Contains compilation errors unrelated to the learning objective |
| 174 | +- Has misleading or unclear instructions |
| 175 | + |
| 176 | +Please open a PR with the fix! Even small corrections are valuable. |
| 177 | + |
| 178 | +#### Have a Better Explanation? |
| 179 | + |
| 180 | +Learning is personal, and sometimes an exercise explanation doesn't click. If you can explain a concept more clearly: |
| 181 | +- Fork the repository |
| 182 | +- Improve the exercise comments and instructions |
| 183 | +- Submit a PR with your improvements |
| 184 | + |
| 185 | +I especially value contributions that make complex concepts more approachable for beginners. |
| 186 | + |
| 187 | +#### Found a CLI Bug or Technical Issue? |
| 188 | + |
| 189 | +The CLI itself is also open for improvements! If you encounter: |
| 190 | +- Bugs in the watch mode, file detection, or command execution |
| 191 | +- Issues with progress tracking or state management |
| 192 | +- Problems with the build system or test runner |
| 193 | +- Any crashes or unexpected behavior |
| 194 | +- Performance issues or resource problems |
| 195 | + |
| 196 | +Please report them or better yet, submit a fix! Technical contributions to the core tool are extremely valuable. |
| 197 | + |
| 198 | +#### New Exercise Ideas |
| 199 | + |
| 200 | +Got an idea for teaching a Swift concept better? I'd love to see it! |
| 201 | + |
| 202 | +1. Create a new Swift file in the appropriate category directory |
| 203 | +2. Add the exercise metadata to `exercises.json` |
| 204 | +3. Include: |
| 205 | + - Clear learning objectives |
| 206 | + - Step-by-step instructions |
| 207 | + - Helpful hints |
| 208 | + - Test cases that guide learning |
| 209 | +4. Submit a pull request |
| 210 | + |
| 211 | +#### Improving Documentation |
| 212 | + |
| 213 | +- Found a typo? |
| 214 | +- Have a clearer way to explain something? |
| 215 | +- Want to add examples? |
| 216 | + |
| 217 | +Documentation improvements are always welcome! |
| 218 | + |
| 219 | +### Contribution Guidelines |
| 220 | + |
| 221 | +1. **Test Your Changes**: Make sure all exercises compile and run correctly |
| 222 | +2. **Follow Existing Patterns**: Look at existing exercises for style and structure |
| 223 | +3. **Keep It Focused**: Each exercise should teach one concept clearly |
| 224 | +4. **Be Encouraging**: Write hints and messages that encourage learners |
| 225 | +5. **Consider Difficulty**: Place exercises appropriately in the progression |
| 226 | + |
| 227 | +### Submitting a Pull Request |
| 228 | + |
| 229 | +1. Fork the repository |
| 230 | +2. Create a feature branch (`git checkout -b improve-optionals-exercise`) |
| 231 | +3. Make your changes |
| 232 | +4. Test thoroughly (`make test`) |
| 233 | +5. Commit with clear messages |
| 234 | +6. Push to your fork |
| 235 | +7. Open a PR with a description of what you changed and why |
| 236 | + |
| 237 | +### Report Issues |
| 238 | + |
| 239 | +Not ready to fix it yourself? No problem! Open an issue describing: |
| 240 | +- Which exercise has the problem (if exercise-related) |
| 241 | +- What you expected to happen |
| 242 | +- What actually happened |
| 243 | +- Any error messages you saw |
| 244 | +- Your environment (macOS version, Swift version, etc.) |
| 245 | + |
| 246 | +Every contribution, no matter how small, helps make Swiftlings better for everyone learning Swift! |
| 247 | + |
| 248 | +## License |
| 249 | + |
| 250 | +MIT License - see [LICENSE](LICENSE) file for details. |
| 251 | + |
| 252 | +## Acknowledgments |
| 253 | + |
| 254 | +Inspired by [Rustlings](https://github.com/rust-lang/rustlings), the fantastic Rust learning tool. |
0 commit comments