Compare arrays in swift

前端 未结 6 1224
死守一世寂寞
死守一世寂寞 2020-11-30 02:59

Trying to understand how swift compares arrays.

var myArray1 : [String] = [\"1\",\"2\",\"3\",\"4\",\"5\"]
var myArray2 : [String] = [\"1\",\"2\",\"3\",\"4\",         


        
6条回答
  •  半阙折子戏
    2020-11-30 03:35

    Arrays conform to Equatable in Swift 4.1, negating the caveats mentioned in previous answers. This is available in Xcode 9.3.

    https://swift.org/blog/conditional-conformance/

    But just because they implemented == did not mean Array or Optional conformed to Equatable. Since these types can store non-equatable types, we needed to be able to express that they are equatable only when storing an equatable type.

    This meant these == operators had a big limitation: they couldn’t be used two levels deep.

    With conditional conformance, we can now fix this. It allows us to write that these types conform to Equatable—using the already-defined == operator—if the types they are based on are equatable.

提交回复
热议问题