[使用]:返回排序后的元素序列。
你可以通过调用这个方法对符合“Comparable”协议的任何元素序列进行排序。
1、默认元素序列按【升序】排序。
/// Strings in Swift conform to the `Comparable` protocol
/// let students: Set = ["Kofi", "Abena", "Peter", "Kweku", "Akosua"]
/// let sortedStudents = students.sorted()
/// print(sortedStudents)
/// // Prints "["Abena", "Akosua", "Kofi", "Kweku", "Peter"]"
2、修改元素序列按【降序】排序。
/// let descendingStudents = students.sorted(by: >)
/// print(descendingStudents)
/// // Prints "["Peter", "Kweku", "Kofi", "Akosua", "Abena"]"
网友评论