My code has 2 textfields one for int and the other for string. The way the code is supposed to be sorted is by ascending alphabetical order for the string (a-z)then by descending order for the int (9-1).So i entered 2 entries in a,2 a,1 order but the way the list is being displayed is a,2 a,1 which is not the sorted order. How can I keep the sorted order?
VIEWCONTROLLER
@IBAction func move(_ sender: Any) {
yourArray.append((textA.text!))
number.append(Int(textB.text!)!)
let tuples = zip(yourArray,number)
let sorted = tuples.sorted(by: { this, next in
if this.0 < next.0 {
return true
} else if this.0 == next.0 {
return this.1 < next.1
} else {
return false
}})
bad.mm.append(String(describing: sorted.map { " \($0)" }.joined(separator:"\n")))
}
struct bad {
static var mm = [String]()}
VIEWCONTROLLER2
override func viewDidLoad() {
super.viewDidLoad()
let defaults = UserDefaults.standard
defaults.set(benCarson.text, forKey: "SavedStringArray2")
defaults.synchronize()
benCarson.text = String(describing: bad.mm)
benCarson.numberOfLines = 5000
}
Picture of result https://i.stack.imgur.com/7MM4l.jpg