1

I was wondering if anyone knew if the XCAsset symbols provided in autocompletion can be used in any way, I imagine something but it didn't worked.

enter image description here

Xcode propose all the images, it looks really interesting but if it's just to "show" I would be sad :(

enter image description here

Tancrede Chazallet
  • 7,035
  • 6
  • 41
  • 62

1 Answers1

3

What you're seeing there is an image literal. It's not the name for the image, it is the image — so using one is equivalent to the entire UIImage(named: "icon-stack") call, not just the "icon-stack" string within that call.

If you assign one of these directly to a var or let, you'll see that its inferred type is UIImage (or NSImage if targeting macOS):

image literal inferred type

rickster
  • 124,678
  • 26
  • 272
  • 326
  • Maybe you can confirm me, but it seems to work only with Swift 3.0 – Tancrede Chazallet Oct 26 '16 at 16:33
  • Yes, image literals (for asset catalogs in an Xcode project) are for Swift 3 only. Image literals in general have been around longer, but before Xcode 8 / Swift 3 could be used only in playgrounds. – rickster Oct 26 '16 at 16:49