struct不保持排序顺序(swift4)

时间:2017-10-01 00:52:21

标签: ios sorting struct nsuserdefaults swift4

我的代码有2个文本字段,一个用于int,另一个用于字符串。应该对代码进行排序的方式是按字母顺序(az)按字母顺序递增,然后按int(9-1)的降序排序。所以我在a,2a,1顺序中输入2个条目但是顺序正在显示的列表是a,2a,1,它不是排序顺序。如何保留排序顺序?

的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

}

enter image description here

0 个答案:

没有答案