Created
June 30, 2016 09:47
-
-
Save batitous/e6d6ca5889f63b55d892a4dce16a720d to your computer and use it in GitHub Desktop.
Compare 2 optionnel arrays in Swift, thanks to Sysy !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// At present, Optional<Array<T>> is not possible to make equatable even though T might be. | |
// This fakes that that behaviour to make comparisons between optional arrays simpler. | |
func !=<C: Equatable>(lhs: [C]?, rhs: [C]?) -> Bool { | |
return !(lhs == rhs) | |
} | |
func ==<C: Equatable>(lhs: [C]?, rhs: [C]?) -> Bool { | |
switch (lhs, rhs) { | |
case (.Some(let lhs), .Some(let rhs)): | |
return lhs == rhs | |
case (.None, .None): | |
return true | |
default: | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let arr: [Int]? = nil
let arr2: [Int] = [1]
let equal = arr == arr2