After playing with this for a while to find a practical example for the original answer, I found a much simpler difference: C, elementsEqualyou can compare collections of different types, such as Array, RandomAccessSliceand Set, and when ==you cannot do this:
let array = [1, 2, 3]
let slice = 1...3
let set: Set<Int> = [1, 2, 3]
array.elementsEqual(slice)
array.elementsEqual(set)
array == slice
array == set
As for a completely different one, @Hamish provided implementation links in the comments below, which I will use for better visibility:
My original answer:
Here is an example of a playground for you that shows that there is a difference:
import Foundation
struct TestObject: Equatable {
let id: Int
static func ==(lhs: TestObject, rhs: TestObject) -> Bool {
return false
}
}
let test1 = TestObject(id: 1)
let test2 = TestObject(id: 1)
test1 == test2
var testArray = [test1, test2]
var copiedTestArray = testArray
testArray == copiedTestArray
testArray.elementsEqual(copiedTestArray)
, - , , == - memoryLocationIsEqual || elementsEqual ( , ), elementsEqual , == , elementsEqual .