I have the following struct, with some properties:
struct Partner {
let id: Int
let nome: String
let icone: String
var isSelected : Bool
}
So I initialize a simple array and put some data in there:
var parceiros : [Partner] = [
Partner(id: 1, nome: "Personal Profile", icone: "btPersonal",isSelected : true),
Partner(id: 2, nome: "Professional Profile", icone: "btProfessional", isSelected: false)
]
But when I want to change the "isSelected" property with the high-order function Map, in the swift 4, the array don't update at all. Its weird because the var "_parceiro" have the right value in the return loop. But after the function the array returns to the original value.
private func select(partner: Partner){
let _ = parceiros.map { (parceiro) -> Partner in
var _parceiro = parceiro
_parceiro.isSelected = parceiro.id == partner.id ? true : false
return _parceiro
}
}
parceiros.map { (parceiro) -> Partner intelling onResult of call to 'map' is unused?map()returns the transformed result, it doesn't modify the current object calling it, it's not a mutating method.