A Swift package providing a collection of powerful macros for enhanced enum handling and code generation.
QizhMacroKit uses Swift Macros (introduced in Swift 5.9) and requires Swift 6.2+ to generate compile-time code, reducing boilerplate and enhancing enum ergonomics. All macros are powered by SwiftSyntax and execute during compilation with zero runtime overhead.
| Macro | Type | Description |
|---|---|---|
@CaseName |
Attached | Generates a caseName property returning the case name as a String |
@CaseValue |
Attached | Generates properties to extract associated values from cases |
@IsCase |
Attached | Generates is<CaseName> boolean properties and membership checking |
@IsNotCase |
Attached | Generates isNot<CaseName> boolean properties |
@OptionSet<RawType> |
Attached | Creates an OptionSet from a struct with nested Options enum |
#stringify |
Freestanding | Converts an expression to its source text |
#dictionarify |
Freestanding | Returns a key-value pair with source text and evaluated value |
- Swift: 6.2+
- Platforms: iOS 17+, macOS 14+, Mac Catalyst 14+
- Dependencies: swift-syntax 602.0.0+
Add QizhMacroKit to your Package.swift:
dependencies: [
.package(url: "https://github.com/qizh/QizhMacroKit.git", from: "1.1.0")
]Then add the dependency to your target:
targets: [
.target(
name: "YourTarget",
dependencies: ["QizhMacroKit"]
)
]- File → Add Package Dependencies...
- Enter:
https://github.com/qizh/QizhMacroKit.git - Select version requirements
- Add to your target
import QizhMacroKit@CaseName
enum Status {
case idle
case loading
case success(Data)
case failure(Error)
}
let status = Status.loading
print(status.caseName) // "loading"@IsCase
enum NetworkState {
case disconnected
case connecting
case connected(session: Session)
}
let state = NetworkState.connecting
// Boolean properties
if state.isConnecting {
showLoadingIndicator()
}
// Membership checking
if state.isAmong(.disconnected, .connecting) {
retryConnection()
}@IsNotCase
enum Permission {
case granted
case denied
case notDetermined
}
let permission = Permission.notDetermined
if permission.isNotGranted {
requestPermission()
}@CaseValue
enum Result {
case success(data: Data)
case failure(error: Error)
}
let result = Result.success(data: responseData)
// Optional extraction
if let data = result.successData {
process(data)
}let x = 42
let text = #stringify(x * 2 + 1)
print(text) // "x * 2 + 1"let pair = #dictionarify(2 + 2)
print(pair.key) // "2 + 2"
print(pair.value) // 4Detailed documentation for each component:
- CaseName — Case name as string
- CaseValue — Associated value extraction
- IsCase — Boolean case checking
- IsNotCase — Negated case checking
- Stringify Macros —
#stringifyand#dictionarify
- String Helpers — Case conversion, keyword escaping, backtick handling
- Known Issues — Current limitations and workarounds
- TODO / Roadmap — Planned features and improvements
QizhMacroKit/
├── Sources/
│ ├── QizhMacroKit/ # Public API (macro declarations)
│ ├── QizhMacroKitMacros/ # Macro implementations (SwiftSyntax)
│ │ └── Helpers/ # String manipulation utilities
│ └── QizhMacroKitClient/ # Example usage
├── Tests/
│ ├── CaseNameTests/ # @CaseName macro tests
│ ├── CaseValueTests/ # @CaseValue macro tests
│ ├── IsCaseTests/ # @IsCase macro tests
│ ├── IsNotCaseTests/ # @IsNotCase macro tests
│ ├── OptionSetTests/ # @OptionSet macro tests
│ ├── StringifyTests/ # #stringify / #dictionarify tests
│ ├── DiagnosticTests/ # Diagnostic types tests
│ └── HelperTests/ # String helper extension tests
├── Docs/ # Documentation
├── Package.swift # SPM manifest
├── KNOWN_ISSUES.md # Current limitations
├── TODO.md # Roadmap
├── AGENTS.md # Agent instructions
└── README.md # This file
# Build all targets
swift build
# Build library only (works on Linux)
swift build --target QizhMacroKit
# Run tests
swift test
# Run tests with verbose output
swift test --parallel --verboseContributions are welcome! Please:
- Check TODO.md for planned work
- Review KNOWN_ISSUES.md for bugs to fix
- Open an issue to discuss significant changes
- Submit a PR with tests for new functionality