Struct not keeping tuple in order (swift3)

Hi @timswift, sorry but I don’t really understand what you are trying to achieve. Could you please try to explain what the end result that you want is?

Is it to show the following in ViewController2:

(“a”, 1)
(“a”, 2)

I’m trying to follow your code but can’t make sense of why you are serialising it all to a string like you are in ViewController1. Maybe this would be a better way to write the code:

class ViewController1 {
    
    /// Where we store the data that the user enters
    var pairs = [(String, Int)]()
    
    @IBAction func store(_ sender: Any) {
        let text = textA.text ?? ""
        let num = Int(textB.text ?? "") ?? 0

        var newPairs = pairs
        newPairs.append((text, num))
        newPairs.sort { ... }
        pairs = newPairs
       
        labez.text = pairs.map { String(describing: $0) }.joined(separator: "\n")
    }
} 

You shouldn’t really use the bad struct to be sharing data across the two view controllers, instead you could just pass the pairs array into ViewController2 either via prepareForSegue(...) or when you init ViewController2 depending on your implementation.

Hope that helps!