I have array of objects
let storeArray = [obj1, obj2, obj3]
And I want to remove obj2, how can I remove this with Swift 5?
I have array of objects
let storeArray = [obj1, obj2, obj3]
And I want to remove obj2, how can I remove this with Swift 5?
If you specifically want to remove obj2, you can do this...
var storeArray = [obj1, obj2, obj3]
storeArray.removeAll(where: { $0 == obj2 })
If you know that obj2 is in index 1 of the array and you trust that:
var array = [obj1, obj2, obj3]
guard array.count > 1 else { return }
array.remove(at: 1)
If you want to remove the obj2 without trusting it's index:
var array = [obj1, obj2, obj3]
array.removeAll(where: { $0 == obj2 })
You can try this,
var storeArray = [obj1, obj2, obj3]
storeArray.remove(at: 1)
print(storeArray)