An NSSet
can be converted to Array
using set.allObjects()
but there is no such method in the new Set
(introduced with Swift 1.2). It can still be done by converting Swift Set to NSSet and use the allObjects()
method but that is not optimal.
You can create an array with all elements from a given Swift
Set
simply with
let array = Array(someSet)
This works because Set
conforms to the SequenceType
protocol
and an Array
can be initialized with a sequence. Example:
let mySet = Set(["a", "b", "a"]) // Set<String>
let myArray = Array(mySet) // Array<String>
print(myArray) // [b, a]