Skip to content

Instantly share code, notes, and snippets.

@dkw5877
Created March 28, 2019 17:39
Show Gist options
  • Save dkw5877/e90e9b1a9ef0c22e09635636f63c796e to your computer and use it in GitHub Desktop.
Save dkw5877/e90e9b1a9ef0c22e09635636f63c796e to your computer and use it in GitHub Desktop.
Example of testing equality on collections in Swift with custom structs
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