I have a class
class CardImage {
var imageName: String?
var image : UIImage?
var is_saved = false
}
I have two arrays
var imagesToBeDeleted = [String]()
var cardImages = [CardImage]()
I want to delete elements from cardImages that has property imageName similar to the elements present in imagesToBeDeleted.
EXTRA DETAIL: from the names of both arrays you can figure out that imagesToBeDeleted will be subset of imageName property of cardImages array.
You just have to use filter on cardImages, check if the name of the current card is present in the imagesToBeDeleted array or not and only keep the elements of cardImages that are not present in the other array.
cardImages = cardImages.filter{!imagesToBeDeleted.contains($0.imageName)}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With