Search code examples
swiftxcodesf-symbolsimage-literals

Displaying SF Symbols as an Image Literal?


Xcode will allow me to introduce image literals in code when I start typing image literal and use autocomplete:

enter image description here

With iOS 13, they released SF Symbols that can be introduced into the code like so:

let image = UIImage(systemName: "square.and.arrow.up")

Is there any way to combine the two and see the SF Symbol as an image literal?

When I try double clicking the image, I only see a selection box for the images provided by my xcassets file.


Solution

  • TL;DR Xcode does not support combining the two.


    If you comment the image literal code, you can see that it's actually inserting the following code:

    static let image = #imageLiteral(resourceName: )
    

    Attempting to do either of the following does not work:

    • #imageLiteral(resourceName: "trash")
    • #imageLiteral(systemName: "trash")

    Therefore, I don't think image literals with SF Symbols are supported as of Xcode 11.3.1.