Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 10 - image literals no longer available

Xcode 10 Release Notes: "Code Completion for Swift image literals has been removed in Xcode 10"

So it's not a bug that I couldn't add images in the code (and run older projects). How do we then add images from now on in the code as just typing UIImageView(image: won't accept any png or jpeg.

let cellImage: UIImageView = {     let image = UIImageView(image: ???))      return image }() 

System: macOS Mojave
Xcode: Xcode 10 Beta 4

like image 783
Pawel Cichonski Avatar asked Jul 18 '18 08:07

Pawel Cichonski


People also ask

How do you open color literals in Xcode 13?

@Stevie, try typing in a empty line #colorLiteral, upon typing ( the square icon for literal will show up.

How do I add an image to Xcode?

Drag and drop image onto Xcode's assets catalog. Or, click on a plus button at the very bottom of the Assets navigator view and then select “New Image Set”. After that, drag and drop an image into the newly create Image Set, placing it at appropriate 1x, 2x or 3x slot.


1 Answers

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.

enter image description here

 

Double click on this icon and it will open the media library right side of it.

enter image description here

 

Just choose your imagem and it work like before!

enter image description here

like image 58
Daniel Arantes Loverde Avatar answered Oct 04 '22 20:10

Daniel Arantes Loverde