15

I am trying to set image to UIImageView. Its working well in older version.

In Xcode 9.4.1

enter image description here

But in Xcode 10

enter image description here

When I am trying to type name of image, image suggestion is not showing.

Even "Image Literal" is not working. Double clicking on above icon also not working.

Is there any setting in Xcode preferences?

How to enable image suggestion like before?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jay Patel
  • 2,642
  • 2
  • 18
  • 40
  • 1
    Possible duplicate of [Xcode 10 - image literals no longer available](https://stackoverflow.com/questions/51397347/xcode-10-image-literals-no-longer-available) – Cœur Sep 27 '18 at 05:33
  • I feel that the other question may bring better answers than yours, that's why I link it in that direction. It takes many voters to close a question anyway, so you may be safe if you disagree. – Cœur Sep 29 '18 at 01:47
  • Also, you can't see it because you have less than 10k reputation, but there is a moderator comment on this page stating: _"Please don't post identical answers to multiple questions. Instead, tailor the answer to the question asked. If the questions are exact duplicates of each other, please vote/flag to close instead. – Samuel Liew♦ Sep 17 at 14:13"_ – Cœur Sep 29 '18 at 01:50

4 Answers4

21

In Xcode 10 and Swift 4.2, only the code completion function (or auto-complete) of the Xcode IDE has been discontinued for the old way. Here is the new way:

Just type image literal and it will complete with default icon. Double click on this icon and it will open the media library right side of it.

Just choose your image and it work like before!

Hope I am able to help you!

Mohd Asim
  • 2,171
  • 1
  • 18
  • 15
9

https://download.developer.apple.com/Developer_Tools/Xcode_10_beta_3/Release_Notes_for_Xcode_10_beta_3.pdf

Code Completion for Swift image literals has been removed in Xcode 10. (38087260) enter image description here

user2481332
  • 111
  • 2
  • So how can we use images without name? – Jay Patel Jul 09 '18 at 09:54
  • 4
    Do you know why they removed this? Is it going to be reenabled? – Damian Dudycz Aug 14 '18 at 13:43
  • I just downloaded Xcode 10 and no luck. Seems like it's still gone. Can't find any mention of its depreciation in the release notes. – David Sep 18 '18 at 14:52
  • 7
    For now you can autocomplete "Image Literal" option (either type image, or literal), confirm with enter then double click to select icon from the list. Not as convenient as typing asset name though. – frin Sep 19 '18 at 08:28
4

There seem to be some real issues with how Xcode 10 handles image literals, especially when the name you provide your assets doesn't align with the filename of those assets.

The following are the steps I've found will restore image literal previews.

Add an image via the media library picker.

Add an image via the media library picker.

If you have multiple resolutions for your image (e.g. @1x, @2x, @3x), Xcode will inconveniently drop them all into your code and throw an error to let you know you've done something naughty.

Consecutive statements error.

Delete two of the faulty image previews, if necessary. You may be left with a default image icon instead of a preview of your actual image.

Default image icons.

Comment out the lines on which you're setting the image. You'll see the image literal references the filename of your asset rather than the name you've provided in the asset catalog.

If you've renamed your assets after adding them to your asset catalog, this seems to sometimes prevent Xcode from reading the asset appropriately.

Filenames.

Change the filenames to the appropriate asset names.

You can find the asset names in your asset catalog.

Asset names in catalog.

Asset names in code.

Uncomment the code and, if the default image icon is still visible, double click on the image icon. It should then display a preview of your actual asset.

You may also need to clean and rebuild your project.

Asset previews.

Ian Rahman
  • 315
  • 3
  • 7
0

use command + shift + M to popup the Media Library then Simply Drag and Drop into your Code

OR

add image via code

Vishal Shelake
  • 572
  • 1
  • 8
  • 12