A Swift development environment for solving Advent of Code challenges.
This project is configured to run in GitHub Codespaces with a complete Swift development environment.
- Push this repository to GitHub
- Click on "Code" → "Codespaces" → "Create codespace on main"
- Wait for the environment to build (Swift 6.2 will be installed automatically)
- Start coding!
.
├── .devcontainer/ # Codespace configuration
│ └── devcontainer.json # Container setup with Swift and extensions
├── .vscode/ # VS Code configuration
│ ├── launch.json # Debugging configurations
│ └── tasks.json # Build and test tasks
├── Sources/ # Source code
│ ├── main.swift # Main entry point
│ └── Day1.swift # Example day template
├── Tests/ # Unit tests
│ └── Day1Tests.swift # Example test template
├── Inputs/ # Puzzle inputs
│ └── day1.txt # Place your puzzle inputs here
├── .swiftlint.yml # SwiftLint configuration
└── Package.swift # Swift Package Manager configuration
- Add a new day: Create a new file like
Sources/DayN.swiftusing theDay1.swifttemplate - Add input: Place your puzzle input in
Inputs/dayN.txt - Implement solution: Fill in the
solvePart1()andsolvePart2()functions - Run: Use
swift runor press F5 to debug - Test: Add tests in
Tests/DayNTests.swiftand run withswift test
- Build:
swift buildor Cmd+Shift+B - Run:
swift run - Test:
swift testor Cmd+Shift+T - Debug: Press F5 or use Run → Start Debugging
- Clean:
swift package clean - Lint: SwiftLint runs automatically with the VS Code extension
This project includes SwiftLint for maintaining code quality and consistency:
- Automatic linting: The SwiftLint VS Code extension provides real-time feedback
- Configuration: Customize rules in .swiftlint.yml
- AoC-friendly settings:
- Single-character variable names allowed (
i,j,k,x,y,z) - Reasonable line and function length limits
- Format-on-save enabled
- Single-character variable names allowed (
The configuration is optimized for Advent of Code challenges while maintaining good code practices.
Edit Package.swift to add Swift packages. Common useful packages for AoC:
dependencies: [
.package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
]Then add them to your target's dependencies array.
The project includes LLDB debugging configuration:
- Set breakpoints by clicking in the gutter
- Press F5 to start debugging
- Use the Debug Console to inspect variables
- Keep each day's solution in its own file
- Use the
Inputs/directory for puzzle inputs - Write tests for the example inputs first
- Use Swift's powerful features: pattern matching, optionals, collections
- SwiftLint helps catch common mistakes and maintain clean code
- Swift Language Support (
swiftlang.swift-vscode) - Syntax highlighting, code completion - CodeLLDB (
vadimcn.vscode-lldb) - Debugging support for Swift - CMake Tools (
ms-vscode.cmake-tools) - Build system support - SwiftLint (
vknabel.vscode-swiftlint) - Code linting and style enforcement
Happy coding! 🚀