I'm working on a swift project where I create a custom keyboard. In my ViewController, I store and mutate an array of UIImages. Then, in my Keyboard module in my keyboardViewcontroller.swift I would like to use the data I have in this array to create buttons. However, when I try to access the array in KeyBoardViewController it seems to give me an empty array and throws an index out of bounds error. What is strange to me is that in ViewController I print out the size of my array and it is definitely not empty. Here is how I'm storing the array:
import UIKit
class Main {
var pics :[UIImage]
init(pics : [UIImage]) {
self.pics = [UIImage]()
}
}
var instance = Main(pics: [UIImage]())
In ViewController I mutate it with instance.pics.append...
In my KeyboardViewController:
for image in instance.pics {
...
}
Why would this show as an empty array in KeyboardViewController? Thanks
picsargument toself.pics, you are assigning a new, empty array ([UIImage]()).UIImage. What would you expect to happen?