[Swift]String型配列の要素を降順でソートする

書式
string配列名.sort { $0 > $1 }
使用例

var cftArr = ["st", "in", "ark", "game", "com"]
print("string配列をソートbefore: ")
print(cftArr)
cftArr.sort { $0 > $1 }
print("string配列をソートafter:")
print(cftArr)

結果
$ swift strsort.swift
string配列をソートbefore:
[“st", “in", “ark", “game", “com"]
string配列をソートafter:
[“st", “in", “game", “com", “ark"]

Swift

Posted by arkgame