I'm looking for sort my dropdown list into ascending order.

let set = NSSet(array: arrTemp as! [Any])
let arrNewPredicated = set.allObjects as NSArray
arrAllArrayCode = NSMutableArray (array: arrNewPredicated)

I have 17 elements that looks like this

[0]=(NSTaggedPointerString*)"AAA"
[1]=(NSTaggedPointerString*)"CCC"
[2]=(NSTaggedPointerString*)"BBB"

I would like to order them by ascending order.

3 Answers

1
Alastar On

I supposed arrTemp is an array of Strings so:

first of all you're using Swift so as LeoDabus suggests drop NS prefix. Than build your set:

let arrayOfStrings = ["beta", "omega", "alpha", "teta"]
let set = Set<String>(arrayOfStrings)

then just sort it:

let sorted = set.sorted()
0
Agisight On

If you use an array of sortable elements:

let arrTemp = ["AAA", "CCC", "BBB"]
let set = Set(arrTemp)
let arrNewPredicated = set.sorted { (str1, str2) -> Bool in
    return str1 < str2
    // or use
    // return str2 < str1
}
0
jo7332 On

I found the correct line of code for my issues. If that can help someone..

let set = NSSet(array: arrTemp as! [Any])
let arrNewPredicated = set.allObjects as NSArray
let sortarray = arrNewPredicated.sortedArray(using: [NSSortDescriptor(key: "", ascending: true)])  as NSArray