Xcode 8 Image Completion

Xcode 8 Image Completion

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)
Sample Image

Update 2

Xcode 11.2.1, this is not appearing anymore.

Xcode 8 Image Completion

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)
Sample Image

Update 2

Xcode 11.2.1, this is not appearing anymore.

Is there a way to turn off Xcode 8's autocomplete for image names?

No this unfortunately can't be turned off, and nothing states that this is fixed in the Xcode 8.1 Release Notes.

It should either be fixed or you should have the opportunity to turn it off. The functionality is kind of good when it´s used for it´s purpose only, as I describe in this post.

But the issue is that Xcode 8 is inserting images inline in source when it can't possibly make any sense as you mention. For example, if you have a for iteration and type for x in to start a loop and you have any image in the project whose name matches "in" using this syntax.

Annoying issue, that I hope Apple will fix soon, because the feature is good when it´s used for images only.

Update:

Just confirmed that this is still an issue in Xcode 8.1 stable version.

Update:

This functionality remains in Xcode Version 9.0 beta 6 (9M214v)
Sample Image

Update

This seems to be fixed in Xcode 10 now.

Why can't I use the new inline #imageLiteral syntax in Xcode 8? Expected expression in return result

You should check Swift Version.

Build Settings > Use Legacy Swift Language Version = NO

Image Literal is only supported on Swift3.0, not Swift2.3.

Adding captured image to next view Swift 3 Xcode 8

I expect the key thing here will be to change this:

var scan: UIImage!

to this:

var scan: [UIImage] = []()

Now you've got an array you can append to, adding each of your images in prepare. Of course you will also have to change the code in the second view controller to look at how many images you've got and assign them to your various image views, but that's a trivial change to make.



Related Topics



Leave a reply



Submit