Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to use the new #imageLiteral inline image assignment from your assets folder in Xcode 8, where instead of the whole UIImage(named: "") syntax it's just the image displayed, as shown here.

But when I do, I get the error "Expected expression in return result" when it's a function.

Here's a simple example:

func img() -> UIImage {
    return #imageLiteral(resourceName: "small-checkmark")
}

Where in Xcode it displays the small-checkmark as would be expected, but it won't compile due to the above error. Everything is autocompleted for me, the file is in the assets folder (a PDF). I don't understand what's going wrong. If I just return UIImage() it compiles fine.

What should I be doing?

like image 282
Doug Smith Avatar asked Oct 12 '16 00:10

Doug Smith


1 Answers

You should check Swift Version.

Build Settings > Use Legacy Swift Language Version = NO

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

like image 194
Kentaro Matsumae Avatar answered Nov 15 '22 20:11

Kentaro Matsumae