Why can't I use the new built-in C # imageLiteral syntax in Xcode 8? "Expected Returns"

I am trying to use the new destination of the #imageLiteral embedded image from the folder with your resources in Xcode 8, where instead of the syntax of all UIImage(named: "") , only the image is displayed, as shown here .

But when I do this, I get the error "Expected expression as a result of return" when it is a function.

Here is a simple example:

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

Where Xcode displays a small-checkmark , as you would expect, but it will not compile due to the above error. For me, everything is autocomplete, the file is located in the resource folder (in PDF format). I do not understand what's going on. If I just return it to UIImage() , it compiles fine.

What should I do?

+5
source share
1 answer

You should check the version of Swift.

 Build Settings > Use Legacy Swift Language Version = NO 

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

+5
source

Source: https://habr.com/ru/post/1258059/


All Articles