After encountering similar behavior in my own code, I spent some time investigating why the array equality check disregards order. My experiments indicated that the way Swift handles optional unwrapping during the equality check might be causing this effect. It appears that Swift treats nil and non-nil elements in such a manner that the order becomes irrelevant, possibly to maintain consistency when comparing optionals. I believe this behavior is by design rather than a bug, and developers should be mindful of this when comparing arrays of optionals.
i noticed swift compares only promised values. having nil in the mix makes order less relevant. seems like a side-effect in handling optionals rather then a bug, though it’s kinda confusing sometimes.
hey, i think its intentional behavior, kinda like how swift handles optionals. the order isnt added to the comparison, so it does what its designed to do, even tho it might seem weird at first
During my experiments with URL arrays in Swift, I observed similar behavior. In one case, I discovered that when an improperly formatted string returns nil, the equality operator seemed to overlook the order when comparing the arrays. It initially appeared as if Swift was comparing the collections as sets rather than sequences. However, after verifying that properly initialized URL instances behave correctly in ordered arrays, I concluded that the issue likely stems from the optional handling. This unexpected ordering result might be a bug and is worth further investigation in the current Swift version.