Swift 4.0 forEach problem


(Edward Connell) #1

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


(Slava Pestov) #2

Thanks, do you mind filing a bug at bugs.swift.org <http://bugs.swift.org/>?

Slava

···

On May 19, 2017, at 4:18 PM, Edward Connell via swift-users <swift-users@swift.org> wrote:

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
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users