Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

ios - Xcode 8 Image Completion

In Xcode 8, you have images autocompleted while typing.

Question is : Why?

I tried to init UIImage with the suggested result, but it doesn't work.

Inside UIImage Outside UIImage

Does anyone know how to use it ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Xcode 8 will automatically recognize any images you’ve got in an Asset Catalog and offer them up as a suggestion inside of a UIImage initializer.

So basically what you need to do is just the following (as you have done in your question, but there must be something else that′s disturbing it):

let i = voiture // image name

And then just use i when you want to set an image.

Under the hood it’s creating code that looks like this: #imageLiteral(resourceName: "voiture.png"). But inline in the source editor, you’ll just see the file name of the image. The #imageLiteral syntax is only recognised on Swift 3 or later.

Here is a demonstration video link where I do this and here is a link to a sample project that I created.

Note that you need to click on the instellisense suggestion so that you see a thumbnail of the image in the code and then the image name.

Update 1

This functionality remains in Xcode Version 9.0 beta 6 (9M214v) enter image description here

Update 2

Xcode 11.2.1, this is not appearing anymore.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...