I have an array with quite a lot of elements in it. I want to remove an element by the value rather than by the key. It seems you have to do this:
array = array.filter() { $0 !== value }
For me coming from a Lua background, this seems somewhat equivalent to this Lua code:
for k,v in pairs(array) do
if v == value then table.remove(array, k) end
end
This is a slow method, and a faster way in Lua is to set the key as the value:
array = {[value] = "something"}
array[value] = nil
Is there any equivalent to this in Swift? In my mind, a filter checks through every element, so I feel like there must be a faster way. If you use a dictionary, is it any better?