Created
November 12, 2019 05:51
-
-
Save naveedmcs/69a3f6e7ab5df5736b7457f06d1aec4f to your computer and use it in GitHub Desktop.
check elements are equal between two array
This file contains hidden or 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
| 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