Suppose I have two array of same object type, Now I want to update all the elements of first array based on some key of another array. I want to update isSelected to true if myArray id ,matches with testArray id.
I can ietrate through myArray using for loop and check every id which is found in the testArray and based on that index isSelected value can be updated. But I am wondering if I can use higher order function like contains or filter for this use case.
class MyObject
{
var id: Int
var isSelected:Bool?
var value: String
}
var myArray = [{id: 1, isSelected: nil, value: abcd}, {id: 2,
isSelected: nil, value: xyz}, {id: 3, isSelected: nil, value: hghghg} ]
var testArray = [{id: 1, isSelected: nil, value: abcd}, {id: 2,
isSelected: nil, value: xyz}]
let resultArray = [{id: 1, isSelected: true, value: abcd}, {id: 2,
isSelected: true, value: xyz}, {id: 3, isSelected: nil, value: hghghg}]