I’m trying to load an SVG image in a SwiftUI project using the SVGKit library, but the SVG fails to load, and I encounter the following error:
Assertion failure in +[SVGLength pixelsPerInchForCurrentDevice], SVGLength.m:238
I’ve tried two approaches to load the SVG file:
if let filePath = Bundle.main.path(forResource: "rat", ofType: "svg"),
let svgImage = SVGKImage(contentsOfFile: filePath) {
Image(uiImage: svgImage.uiImage)
.resizable()
.scaledToFit()
} else {
Text("Failed to load SVG")
.foregroundColor(.red)
}
if let svgImage = SVGKImage(named: "rat") {
Image(uiImage: svgImage.uiImage)
.resizable()
.scaledToFit()
} else {
Text("Failed to load SVG")
.foregroundColor(.red)
}
The Issue: Both approaches fail. The first method throws the error mentioned above, and the second method shows the warning:
[SVGKImage] WARNING: not caching the output for new SVG image with name = rat, because it failed to load correctly.
What I've Tried:
this is the SVG i am trying to display text
Questions: Is this error related to device-specific DPI settings, as hinted by the pixelsPerInchForCurrentDevice method? Does SVGKit require any special configuration to handle modern SVGs? Are there any known limitations with SVGKit for certain types of SVG files?
I don't know why but I changed library to load SVG than it's working this is new library I used https://github.com/exyte/SVGView than it's working but I don't know why not working in SVGKit as that is widely used if anyone know that answer it