A personal library of LeetCode solutions in Swift 6, built with Swift Testing and a test-driven workflow.
Each problem lives in a self-contained enum (P0001, P0017, …) with public methods matching LeetCode's function signatures. Every solution carries full problem metadata and complexity analysis in its DocString — browsable in Xcode Quick Help and the hosted DocC site.
.
├── swift/ Swift Package root
│ ├── Package.swift
│ ├── Sources/LeetCode/ Problem namespaces (P0001, P0026, …)
│ │ └── LeetCode.docc/ Documentation catalog
│ ├── Tests/LeetCodeTests/ Swift Testing suites
│ └── _templates/ File templates and Xcode .codesnippet files
└── .github/workflows/ CI pipeline and DocC deployment
Source files use the problem number and title (17.LetterCombinations.swift) for natural filesystem sorting. Enums use zero-padded names (P0017) for correct ordering in the documentation browser.
Implementation files contain the problem link, description, and complexity analysis. Test files contain constraints and example data. This keeps solution files focused strictly on logic.
- Scaffold — use the
lcsolandlctestXcode snippets, or copy files fromswift/_templates/ - Test — fill in LeetCode's examples and constraints
- Solve — implement until all tests pass
- Document — add time and space complexity to the DocString
- Update docs — run
swift generate-docc-topics.swiftto update the documentation catalog
To install Xcode snippets, copy the .codesnippet files from swift/_templates/ to ~/Library/Developer/Xcode/UserData/CodeSnippets.
When a problem has more than one interesting approach, add each as a separate static method. Keep LeetCode's original function name for the primary solution and append a descriptive suffix for alternatives:
public enum P0518 {
/// Top-down memoization.
public static func change(_ amount: Int, _ coins: [Int]) -> Int { … }
/// Bottom-up tabulation.
public static func changeTabulation(_ amount: Int, _ coins: [Int]) -> Int { … }
}Each variant should carry its own - Complexity: annotation. Tests cover every variant.
From the swift/ directory:
swift build
swift test
swift test --filter LetterCombinations # by name
swift test --filter P0017 # by numberEvery push to main triggers a pipeline that runs tests with code coverage, generates a coverage report, and deploys updated documentation to GitHub Pages. Pull requests run the test suite only.
Documentation is generated with DocC from source comments and published automatically.
# Preview locally
swift package --disable-sandbox preview-documentation --target LeetCodeIn Xcode: Product → Build Documentation.