Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variadic @autoclosure's in Swift 1.2?

Tags:

ios

swift

Now that @autoclosure is part of the parameter declaration as opposed to type, how does one declare that a function takes a variadic amount of autoclosures?

Before:

public func coalesce<T>(all : @autoclosure () -> T? ...) -> T? {
    for f : () -> T? in all {
        if let x = f() { return x }
    }
    return nil
}

After: ???

like image 705
Nathan Kot Avatar asked Apr 20 '15 14:04

Nathan Kot


1 Answers

I opened rdar://19782845, "Swift 1.2: Variadic auto-closures no longer supported," and was given the following response from Apple Developer Relations:

This issue behaves as intended based on the following:

@autoclosure is only allowed on parameters of function type, and varargs is an array. This is not expected to work.

like image 70
stephencelis Avatar answered Nov 17 '22 05:11

stephencelis