[swift-users] Swift 4.0 forEach problem

Edward Connell ewconnell at gmail.com
Fri May 19 18:18:41 CDT 2017


In swift 3.1.1 I was able to have the function below, which "gets" an
optional member collection of objects and calls their setModel member
function. Simple and clean using the forEach method.

public func setModel(model: Model) {

    get()?.forEach { $0.setModel(*model*: model) }
}

However it now fails with Swift 4.0 saying: *Extraneous argument label
'model:' in call*

-------------------
If I rewrite the function as follows, then it compiles with no errors.

public func setModel(model: Model) {
    if let items = get() {
        for item in items {
            item.setModel(model: model)
        }
    }
}


Something is broken...

Any ideas what is wrong?

Thanks, Ed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170519/033d4f27/attachment.html>


More information about the swift-users mailing list