Search code examples
swiftnsset

Set<NSObject>' does not have a member named 'allObjects'


With the original swift I could turn an NSSet (e.g. of Strings) into a typed array with the following syntax:

var stringArray = exampleSet.allObjects as [String]

With the new update I am getting the above error. What is the best way now to convert the Set into an array?


Solution

  • It looks as if your exampleSet is not an NSSet but a native Swift Set which was introduced with Swift 1.2 (compare https://stackoverflow.com/a/28426765/1187415).

    In that case you can convert it to an array simply with

    let array = Array(exampleSet)