How to convert NSSet to [String] array?

前端 未结 4 1413
伪装坚强ぢ
伪装坚强ぢ 2021-02-09 07:00

I have an NSSet of Strings, and I want to convert it into [String]. How do I do that?

4条回答
  •  一整个雨季
    2021-02-09 07:33

    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
    

提交回复
热议问题