为什么我不能在Xcode 8中使用新的内联#imageLiteral语法? “返回结果中的预期表达” [英] Why can't I use the new inline #imageLiteral syntax in Xcode 8? "Expected expression in return result"

查看:716
本文介绍了为什么我不能在Xcode 8中使用新的内联#imageLiteral语法? “返回结果中的预期表达”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Xcode 8中的assets文件夹中使用新的 #imageLiteral 内联图像分配,而不是整个 UIImage(命名:)语法只是显示的图像,如此处所示

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.

这是一个简单的例子:

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

在Xcode中,它会显示小复选标记,但由于上述错误,它将无法编译。一切都为我自动完成,文件位于资源文件夹(PDF)。我不明白出了什么问题。如果我只返回 UIImage()它编译得很好。

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.

我该怎么办?

推荐答案

你应该检查Swift版本。

You should check Swift Version.

Build Settings > Use Legacy Swift Language Version = NO

Image Literal仅支持Swift3.0,而不支持Swift2.3 。

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

这篇关于为什么我不能在Xcode 8中使用新的内联#imageLiteral语法? “返回结果中的预期表达”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆