Jason Eyebe Jason Eyebe - 1 month ago 12
Swift Question

Adding UIImage list to an Array in Swift

I'm trying to code up a simple animation in Swift using a set of 13 .png files via an array of type UIImage. The code is breaking on the following line:

imageList += UIImage(named: imageName)


With the error message "Argument type UIImage does not conform to expected type 'sequence'"

I'm new to Swift. After declaring the array as type UIImage does anybody know why I'm seeing this error? I'm coding in XCode 8.0 Thanks a lot. Full code below:

var imageList = [UIImage]()

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

Answer

You can not creating an array with UIImage

try this way

var imageList = [UIImage]()

and should use append

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