Skip to content

Instantly share code, notes, and snippets.

@naveedmcs
Created November 12, 2019 05:51
Show Gist options
  • Select an option

  • Save naveedmcs/69a3f6e7ab5df5736b7457f06d1aec4f to your computer and use it in GitHub Desktop.

Select an option

Save naveedmcs/69a3f6e7ab5df5736b7457f06d1aec4f to your computer and use it in GitHub Desktop.
check elements are equal between two array
import UIKit
//@nvd
//test example: check elements are equal between two array
struct Person {
var feature: Int?
var selectedId : Int?
}
// confirming equatable protocol
extension Person: Equatable {
static func == (lhs: Person, rhs: Person) -> Bool {
return
lhs.feature == rhs.feature &&
lhs.selectedId == rhs.selectedId
}
}
var personArray1: [Person] = []
personArray1.append(Person(feature: 10, selectedId: 1))
personArray1.append(Person(feature: 20, selectedId: 2))
personArray1.append(Person(feature: 10, selectedId: 3))
var personArray2: [Person] = []
personArray2.append(Person(feature: 10, selectedId: 1))
personArray2.append(Person(feature: 20, selectedId: 2))
//personArray2.append(Person(feature: 10, selectedId: 3))
print(personArray1.elementsEqual(personArray2))
// result false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment