SVG parsing and Android-native format generation in Swift.
Converts SVG files to:
- ImageVector (Jetpack Compose Kotlin code)
- VectorDrawable (Android XML resource)
- Full SVG path parsing (
dattribute) with arc, cubic/quadratic bezier support - Gradient support (linear, radial) with transform matrices
- SVG group hierarchy preservation
- Stroke dash patterns
- CSS inline styles
<use>/<symbol>element expansion- Path data validation and normalization
- Cross-platform: macOS, Linux, Windows
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/DesignPipe/swift-svgkit.git", from: "0.1.0"),
]Then add SVGKit to your target's dependencies:
.target(
name: "MyTarget",
dependencies: [
.product(name: "SVGKit", package: "swift-svgkit"),
]
)import SVGKit
let svgContent = "<svg>...</svg>"
let parsed = try SVGParser.parse(content: svgContent, iconName: "MyIcon")
let kotlin = ImageVectorGenerator.generate(from: parsed, iconName: "MyIcon")
print(kotlin)import SVGKit
let svgContent = "<svg>...</svg>"
let parsed = try SVGParser.parse(content: svgContent, iconName: "MyIcon")
let xml = VectorDrawableXMLGenerator.generate(from: parsed, iconName: "MyIcon")
print(xml)import SVGKit
let svgContent = "<svg>...</svg>"
let xml = try NativeVectorDrawableConverter.convert(svgContent: svgContent, iconName: "MyIcon")
print(xml)- Swift 6.2+
- macOS 13+ / Linux (Ubuntu 22.04+) / Windows
| Package | Purpose |
|---|---|
| swift-log | Structured logging |
| swift-resvg | SVG tree parsing via resvg |
MIT