I have two arrays
let toBeFiltered = ["star0", "star2", "star1", "star0", "star3", "star4"] let theFilter = ["star1", "star3"]
How to filter the first array using the second array? Actually the theFilter
can be changed dynamically, e.g,
let theFilter = ["star2"] or maybe let theFilter = ["star0", "star4", "star2"]
Thanks for your help :)
Use Set Operations
Set(toBeFiltered).intersection(Set(theFilter))
Read more: https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html
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