Swift Set to Array
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: An NSSet can be converted to Array using set.allObjects() but there is no such method in the new Set (introduced with Swift 1.2). It can still be done by converting Swift Set to NSSet and use the allObjects() method but that is not optimal. 回答1: You can create an array with all elements from a given Swift Set simply with let array = Array(someSet) This works because Set conforms to the SequenceType protocol and an Array can be initialized with a sequence. Example: let mySet = Set(["a", "b", "a"]) // Set let myArray = Array(mySet) // Array