Sorting of an array alphabetically in swift

后端 未结 7 1341
感动是毒
感动是毒 2020-12-23 14:03

I am new to swift.I am trying one sample app in which I need to implement the sorting of an array in alphabetical order.I getting the json data and I am adding the titles in

7条回答
  •  独厮守ぢ
    2020-12-23 14:28

    Swift4

    var names = [ "Alpha", "alpha", "bravo", "beta"]
    var sortedNames = names.sorted { $0.localizedCaseInsensitiveCompare($1) == ComparisonResult.orderedAscending }
    print(sortedNames) //Logs ["Alpha", "alpha","beta", "bravo"]
    

提交回复
热议问题