Sorting of an array alphabetically in swift

后端 未结 7 1363
感动是毒
感动是毒 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:32

    Try this one

    var names = [ "Alpha", "alpha", "bravo"]
    var sortedNames = names.sort { $0.localizedCaseInsensitiveCompare($1) == NSComparisonResult.OrderedAscending }
    print(sortedNames) //Logs ["Alpha", "alpha", "bravo"]
    

提交回复
热议问题