【问题标题】:Adding UIImage list to an Array in Swift在 Swift 中将 UIImage 列表添加到数组中
【发布时间】:2016-11-08 15:46:54
【问题描述】:

我正在尝试通过 UIImage 类型的数组使用一组 13 个 .png 文件在 Swift 中编写一个简单的动画。代码在以下行中断:

imageList += UIImage(named: imageName)

带有错误消息“Argument type UIImage does not conform to expected type 'sequence'”

我是 Swift 新手。将数组声明为 UIImage 类型后,有人知道我为什么会看到此错误吗?我正在使用 XCode 8.0 进行编码,非常感谢。完整代码如下:

var imageList = [UIImage]()

override func viewDidLoad() {
    super.viewDidLoad()
    for i in 1...13 {
        let imageName = "\(i)"
        imageList += UIImage(named: imageName)
    }
}

【问题讨论】:

    标签: arrays swift xcode


    【解决方案1】:

    你不能用UIImage创建数组

    试试这个方法

    var imageList = [UIImage]()
    

    并且应该使用附加

    imageList.append(UIImage(named: imageName)!)
    

    【讨论】:

      猜你喜欢
      • 2019-08-07
      • 2014-07-23
      • 2019-01-12
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多