I'm trying to observe array change and bind it to the image of the button.
if the array is empty. set picture of an empty cart.
else set image of a cart.
so what I did was :
let x = itemsArray.observeNext { [weak self] (v) in
let image = v.source.isEmpty ? #imageLiteral(resourceName: "emptyCart") : #imageLiteral(resourceName: "cart")
self?.orderItemsButton.setImage(image, for: .normal)
}
But if I do use this way I must dispose x in viewWillDisappear or something like that...
What is the right way to do it?