How to Convert SVG to SwiftUI
SwiftUI has no built-in way to render an SVG image — the Image view supports PNG, JPEG, PDF, and SF Symbols, but not raw SVG files. The cleanest way to display an SVG in SwiftUI is to convert its path data into a native Shape backed by a Path. This guide shows you how to convert an SVG to SwiftUI in a few seconds using the free SVG to SwiftUI Converter.
Why SwiftUI doesn't support SVG natively
Apple's vector format of choice on iOS is the PDF (and SF Symbols for icons). There is no native SVG view, so importing an SVG into Xcode normally means rasterizing it or hand-tracing the path. Converting the SVG into a SwiftUI Shape avoids both problems: the result is resolution-independent, scales perfectly on every iPhone, iPad, and Mac, and can be filled, stroked, and animated like any other SwiftUI view.
Convert an SVG to a SwiftUI Shape step by step
- Copy your SVG source code. Open the
.svgfile in any text editor and copy the full markup, including the<path>elements. - Paste it into the converter. Drop the code into the SVG to SwiftUI Converter (or upload the file). The conversion runs entirely in your browser — your code never leaves your device.
- Copy the generated SwiftUI Shape. The tool produces a Swift struct conforming to
Shapewith a singlepath(in:)implementation. - Use the Shape in your view. Give it a frame and a fill, and you're done.
Example: an SVG path to a SwiftUI Shape
The converter turns an SVG path into a reusable, scalable Shape that looks like this:
import SwiftUI
struct MyIconShape: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
let width = rect.size.width
let height = rect.size.height
path.move(to: CGPoint(x: 0.5 * width, y: 0.1 * height))
path.addLine(to: CGPoint(x: 0.9 * width, y: 0.9 * height))
path.addLine(to: CGPoint(x: 0.1 * width, y: 0.9 * height))
path.closeSubpath()
return path
}
}Then use it anywhere in your SwiftUI layout:
MyIconShape()
.fill(Color.accentColor)
.frame(width: 100, height: 100)Because the path is expressed relative to the view's rect, the shape scales to whatever frame you give it without losing sharpness — the whole point of converting an SVG path to SwiftUI rather than shipping a bitmap.
Using a specific icon pack?
These guides show how to bring popular icon libraries into SwiftUI and iOS:
- How to use Font Awesome 6 in SwiftUI
- How to use Material Design Icons in SwiftUI
- How to use Heroicons 2 in SwiftUI
- How to use Lucide in SwiftUI
- How to use Bootstrap Icons in SwiftUI
Ready to convert your SVG?
Paste your icon into the SVG to SwiftUI Converter and copy the Swift code straight into Xcode. It's free, runs locally in your browser, and handles everything from a single path to multi-element icons.