[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:
[“ark", “com", “game", “in", “st"]

Swift

Posted by arkgame