Swift SF Symbols - only available in iOS 13.0 or newer error

2.3k Views Asked by At

Been playing around with the SF Symbols and very impressive they are too.

However when I try and use them in code from a number of SF examples I come up with:

let image = UIImage(systemName: "hands.clap"). < init(systemName:) is only available in iOS 13.0 or newer

Do I need to copy the image into the Asset Catalogue as before? What I want to avoid is caveating every instance of their usage, e.g.

if #available(iOS 13.0, *) {
            heartImage = UIImage(systemName: "heart.fill")!
        } else {
            heartImage = UIImage(named: "heart.jpeg")
 }

The file name was copy and pasted as per most of the instructions.

What am I missing?

1

There are 1 best solutions below

0
On BEST ANSWER

Using SFSymbols is only available from iOS 13, however some specific symbols can also have higher deployment version (14 or 15) Check your project version in your App Target "General" tab and minimum deployment of your desired symbol. If you want to use symbols for lower iOS you should mark creating image with if #available(iOS 13.0, *) as you mentioned. If you want to make fallback image for lower iOS , your only option is to create separate asset with UIImage(named: "heart.jpeg") . You can also export your symbols manually adding it to Assset catalogue, however keep in mind that you need to convert it from SVG format so some other format, because iOS lower than version 13 also does not support SVG preserving vector data. exporting symbol