Sorting of sets elements in Swift
Forums:
let chars: Set<Character> = ["A", "B", "C", "D"]
var str = ""
for c in chars {
str += (str == "" ? "" : "; ") + "\(c)"
}
//str is "B; A; C; D"
str = ""
for c in chars.sort() {
str += (str == "" ? "" : "; ") + "\(c)"
}
//str is "A; B; C; D"
- Log in to post comments