Image suggestions are not working Xcode 10
Asked Answered
O

4

16

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?

Outsoar answered 5/7, 2018 at 12:2 Comment(3)
Possible duplicate of Xcode 10 - image literals no longer availablePutrescent
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.Putrescent
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"Putrescent
H
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!

Hysterectomy answered 26/10, 2018 at 7:17 Comment(4)
Worked for me.Thx.Prosecution
Why did they make this change? seems very strange and incovenientAthwart
This didn't work for me until giving the compiler more info e.g.` let image: UIImage = image literal`Lamed
imageliteral should be typed as a single word, without a space, for auto-completion to work. (using Xcode 11)Heckelphone
T
10

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

Tallyman answered 6/7, 2018 at 5:5 Comment(4)
So how can we use images without name?Outsoar
Do you know why they removed this? Is it going to be reenabled?Sanguinaria
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.Armindaarming
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.Og
K
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.

Kaczmarek answered 9/11, 2018 at 16:46 Comment(1)
Protip: Make sure assets are named exactly as you'd like them before adding to your asset catalogKaczmarek
C
0

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

OR

add image via code

Canzone answered 17/10, 2019 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.