SwiftUI Image from SVG file

Until today, I was used to have all my svg files into my assets' folder inside my project

So far so good, a simple Image("example") works great

Today, we decided to make an API request to download these SVG files

I succeed to write the file on disk, fine Data from local URL seems to work too but then, UIImage from Data doesn't work

        let logo = logoFolder.appendingPathComponent("example.svg")

        if fileManager.fileExists(atPath: logo.path) {
            do {
                let data = try Data(contentsOf: logo)

                if let uiImage = UIImage(data: data) {
                    //The conversion above doesn't work
                    completionHandler(.success(Image(uiImage: uiImage)))
                    return
                }
            } catch {}
            completionHandler(.failure(.fetchingFailed))
        }

FYI, the same code works very well to get mp3 or png files

It seems sag are not yet supported in SwiftUI:

https://developer.apple.com/forums/thread/119331

Doc states:

Supported types include PNG, JPEG, HEIC, and more.

But doesn't tell what's in more !?!

Could you add a print to check if nil ?

                print("UIImage", UIImage(data: data))
                if let uiImage = UIImage(data: data) {
                    //The conversion above doesn't work
                    completionHandler(.success(Image(uiImage: uiImage)))
                    return
                }

You should file a bug report for enhancement.

So you get nil in UIImage(data: data).

That seems to confirm that svg is not supported (except if included in Bundle via assets).

SwiftUI Image from SVG file
 
 
Q