Perhaps relatedly, it no longer seems possible to mark typealiased closures as 
@escaping. That was quite handy when you know that closures will always be used 
asynchronously.


Jon


> On Sep 7, 2016, at 6:15 PM, Shawn Erickson via swift-users 
> <[email protected]> wrote:
> 
> I should note that this issue also appeared in an earlier variant of Swift 
> after the addition of @escaping but I was on vacation so didn't get a chance 
> to report it then. It isn't new with the Xcode 8 GM.
> 
> On Wed, Sep 7, 2016 at 3:08 PM Shawn Erickson <[email protected] 
> <mailto:[email protected]>> wrote:
> I like and fully supported the change to @escaping away from @noescape 
> however in a body of code that I am porting to the latest Swift 3 variant (as 
> found in Xcode 8 GM) I am hitting an issue for methods that take an optional 
> completion closure. If optional is involved I can't find a way to apply 
> @escape to the escaping closure. See the following for an basic example...
> 
> Is their a way to do what I need and/or is this an edge case in the 
> implementation of @escaping?
> 
> typealias MyCallback = (String)->()
> 
> // Happy
> func foo1(bar: String, completion: ((String)->())) {
>     completion(bar)
> }
> 
> // Happy
> func foo2(bar: String, completion: MyCallback) {
>     completion(bar)
> }
> 
> // Happy
> func foo3(bar: String, completion: ((String)->())? = nil) {
>     completion?(bar)
> }
> 
> // Happy
> func foo4(bar: String, completion: MyCallback? = nil) {
>     completion?(bar)
> }
> 
> // Happy
> func foo5(bar: String, completion: Optional<MyCallback> = nil) {
>     completion?(bar)
> }
> 
> // Happy
> func foo6(bar: String, completion: @escaping (String)->()) {
>     completion(bar)
> }
> 
> // Happy
> func foo7(bar: String, completion: @escaping MyCallback) {
>     completion(bar)
> }
> 
> // Unhappy...
> // "@escaping attribute only applies to function types"
> func foo8(bar: String, completion: @escaping ((String)->())? = nil) {
>     completion?(bar)
> }
> 
> // Unhappy...
> // "@escaping attribute only applies to function types"
> func foo9(bar: String, completion: @escaping MyCallback? = nil) {
>     completion?(bar)
> }
> 
> // Unhappy...
> // "@escaping attribute only applies to function types"
> func foo10(bar: String, completion: (@escaping ((String)->()))? = nil) {
>     completion?(bar)
> }
> 
> // Unhappy...
> // "@escaping attribute only applies to function types"
> func foo11(bar: String, completion: (@escaping MyCallback)? = nil) {
>     completion?(bar)
> }
> 
> // Unhappy...
> // "@escaping attribute only applies to function types"
> func foo12(bar: String, completion: Optional<@escaping MyCallback> = nil) {
>     completion?(bar)
> }
> _______________________________________________
> swift-users mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to