Hi,
I have a view that displays pictures loaded via web service call. The model for the view is
@ObservedObject private var pictureController: PictureController = PictureController()
The pictures are provided in an array from the controller:
@Published var images:[Picture] = []
and the View displays the data from the array with a List (my Picture class conforms to the Identifiable protocol)
List(pictureController.images){ item in
Text(item.bkey)
}
When loading the pictures from the web service, I store them in a buffer array and afterwards copy the array over to the images array
DispatchQueue.main.async {
self.images = self.imageBuffer
completionHandler(true)
}
I call the controller in the View's onAppear()
self.pictureController.fetchPicturesByTask(bkey_issue: self.bkey_task, completionHandler: { success in
print(self.pictureController.images.count)
self.pictureController.images.forEach(){picture in
print(picture.id)
print(picture.bkey!)
}
})
Here is the thing: self.pictureController.images.count actually return the proper count of items in the array, the prints below show the correct values but for whatever reason, the List in the View does not get updated ...
Just for the sake of it I have also added a button to the View that calls a function on the controller to manually add dummy items to the array and that works perfect ...
Any ideas what I am missing here?
Max