Scenario: An array of strings, many are duplicated.
Goal: Produce a UNIQUE array of strings.
Modus Operandi: I was thinking of converting the array to a set of strings which become unique; from which to generate a new array of unique strings.
Question: How does one convert a Swift array into a Swift Set?
let nonUniqueArray = ["A", "B", "C", "C", "B", "A"] let uniqueArray = Array(Set(nonUniqueArray)) print(uniqueArray)
produces
["C", "B", "A"]
Swift 2.2 produces exactly the same result as well.
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