Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

nsset

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?

like image 425
James Alvarez Avatar asked Mar 06 '15 17:03

James Alvarez


1 Answers

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)
like image 66
Martin R Avatar answered Oct 13 '22 19:10

Martin R