如何在Xcode 8.2中声明UIImage对象

时间:2017-03-25 12:26:03

标签: ios swift xcode

let hopAnimation:[UIImage] = UIImage(named:"background")

我这样做,但Xcode告诉我:

Expected ',' separator Fix-it insert ','

2 个答案:

答案 0 :(得分:1)

我尝试了你的代码。它向我展示了Cannot convert value of type 'UIImage?' to specified type '[UIImage]'。然后我删除了[UIImage]

let hopAnimation = UIImage(named:"background")

现在它没有显示错误

我必须告诉你

[UIImage] is an array of images.Here you are not creating array of image.You create only image.So remove the array of images.

答案 1 :(得分:1)

[UIImage]声明了一系列图像。要创建单个图像,请使用:

var hopAnimation = UIImage(named:"background")