Using Map in Swift to Change Custom Struct Properties

后端 未结 2 362
野性不改
野性不改 2020-11-30 11:45

I have the following struct defined.

struct Person {

    var firstName :String
    var lastName :String
    var active :Bool
}

I have cre

2条回答
  •  遥遥无期
    2020-11-30 12:40

    When using the brackets for arguments so that var works, you have to put the return type as well:

    let inActionPersons = persons.map { (var p) -> Person in
    
        p.active = false
        return p
    }
    

提交回复
热议问题