Created
March 28, 2019 17:39
-
-
Save dkw5877/e90e9b1a9ef0c22e09635636f63c796e to your computer and use it in GitHub Desktop.
Example of testing equality on collections in Swift with custom structs
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
enum AnimalType { | |
case tiger | |
case elephant | |
case otter | |
} | |
struct Animal:Equatable { | |
let name:String | |
let type:AnimalType | |
} | |
let tiger = Animal(name: "Tony", type: .tiger) | |
let elephant = Animal(name: "Dumbo", type: .elephant) | |
let otter = Animal(name: "Steve", type: .otter) | |
let animals1 = [tiger, elephant, otter] | |
let animals2 = [tiger, elephant, otter] | |
isEqual = animals1 == animals2 //true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment