I have two struct and two arrays corresponding to it and I am trying to compare the two array values and print it in one filtered array i did try and use filter but its giving me an error I want to compare an id from both the struct and get one single array
Struct ONE
struct One {
let ID: String
let name: String
let lastName: String
}
Array One
var oneData = [One]()
oneData = [One(ID: "1", name: "hello1", lastName: "last2"), One(ID: "1", name: "hello2", lastName: "last2"), One(ID: "2", name: "hello3", lastName: "last3"), One(ID: "3", name: "hello4", lastName: "last4")]
Struct TWO
struct Two {
let ID: String
let name2: String
let lastName2: String
}
Array Two
var twoData = [Two]()
twoData = [Two(ID: "1", name2: "hello1", lastName2: "last1"), Two(ID: "2", name2: "hello2", lastName2: "last2"), Two(ID: "3", name2: "hello3", lastName2: "last3"), Two(ID: "4", name2: "hello4", lastName2: "last4"), Two(ID: "5", name2: "hello5", lastName2: "last5")]
My filtered Array
var mainArray = [Two]()
Code to that I used to filter which is giving me an error
mainArray = oneData.filter{ $0.ID == twoData.contains(where: $0.ID)}