17

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?

James Alvarez
  • 7,159
  • 6
  • 31
  • 46

2 Answers2

26

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)
Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
0

Looks like 'set' is a keyword. Try using a different variable name

Choppin Broccoli
  • 3,048
  • 2
  • 21
  • 28