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

2

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?

Aft answered 6/3, 2015 at 17:39 Comment(0)
A
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://mcmap.net/q/328026/-how-to-create-array-of-unique-object-list-in-swift).

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

let array = Array(exampleSet)
Agonistic answered 6/3, 2015 at 17:49 Comment(0)
S
0

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

Stark answered 6/3, 2015 at 17:40 Comment(1)
this was just an example, not actually the variable name, ive changed the question - sorry for confusionAft

© 2022 - 2024 — McMap. All rights reserved.