Why is my image not being appended to the array?

前端 未结 2 1565
后悔当初
后悔当初 2021-01-22 14:05

I\'ve a simple model that includes:

var photos: [UIImage]?

I\'ve copied the file zombies.jpg as a file into the project. Then, in a required in

相关标签:
2条回答
  • 2021-01-22 14:27

    You have initialize photos array, and you are using conditional unwrapping, which means if its not nil append but your photos array is nil at the time so it will not append a photo in nil array. You should do something like this var photos:[UIImage] = []

    0 讨论(0)
  • 2021-01-22 14:35

    Better do this:

    var photos : [UIImage?] = []
    

    It initializes an empty array, that is ready to store UIImage objects.

    0 讨论(0)
提交回复
热议问题