I put UIImage in ViewdidLoad by creating an array like the one below. How can I write it when I program it in a two-dimensional array?
@IBOutlet varmainImage:UIImageView!
variableListArray:Array<UIImage>=[ ]
var number : Int!// Number // Respondent modification delivered from previous page
override func viewDidLoad(){
super.viewDidLoad()
// UIImage
let image0:UIImage!=UIImage(named: "img.png")
let image1: UIImage!= UIImage(named: "img.png") // Provisional
// ImageListArray
imageListArray.append(image0)
imageListArray.append(image1)
mainimage.image=imageListArray [number]
}
Swift does not have a special array called a two-dimensional array, but it achieves something similar in the form of an array.
varimageListArray:Array<UIImage>=[]
If you arrange this in two dimensions,
varimageListArray:Array<Array<UIImage>>=[UIImage]]()
Also, as Swift's syntax sugar, the array type can be described as [UIImage]
, so
varimageListArray: [[UIImage]]=[UIImage]]()
You can write it like this.
Accessing elements of an array is required by
imageListArray[2][3]
This is what happens.Same as C.
© 2024 OneMinuteCode. All rights reserved.