How to convert NSSet to [String] array?
问题 I have an NSSet of Strings, and I want to convert it into [String]. How do I do that? 回答1: I would use map : let nss = NSSet(array: ["a", "b", "a", "c"]) let arr = nss.map({ String($0) }) // Swift 2 let arr = map(nss, { "\($0)" }) // Swift 1 回答2: If you have a Set<String> , you can use the Array constructor: let set: Set<String> = // ... let strings = Array(set) Or if you have NSSet, there are a few different options: let set: NSSet = // ... let strings1 = set.allObjects as? [String] // or as