[swift-users] @escaping may only be applied to parameters of function type

Michael Ilseman milseman at apple.com
Tue Sep 13 22:11:11 CDT 2016


TL;DR: The optional is already escaping, due to the fact that “T?" is sugar for Optional<T>, and the noescape-by-default rule only applies to types in immediate parameter position. Current Swift master has much better diagnostics for this case.

There is not currently a general solution involving escapability of closure types used a generic parameters or tuple members, though such a thing would be useful in Swift 4.

> On Sep 13, 2016, at 7:42 PM, Shawn Erickson via swift-users <swift-users at swift.org> wrote:
> 
> The following is the earlier thread I was talking about. 
> 
> [swift-users] Swift 3 (Xcode 8 GM) issue with @escaping  <https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160905/003179.html>
> 
> -Shawn
> 
> On Tue, Sep 13, 2016 at 7:31 PM Shawn Erickson <shawnce at gmail.com <mailto:shawnce at gmail.com>> wrote:
> I hit this issue as well. I had an early email on this list regarding do this topic, not in a situation to search for it. It is a short coming in how escaping can be applied to things like optional closures.
> 
> I was in the process of authoring an email for swift evolution about it and haven't yet gotten around to filing a defect about it.
> 
> -Shawn
> On Tue, Sep 13, 2016 at 7:27 PM Rick Mann via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
> I'm trying to write this function. The errorHandler: parameter is modeled after the NSFileManager enumerate() function. If I include the @escaping you see there, I get the error "@escaping may only be applied to parameters of function type".
> 
> The second parameter, iterator:, seems to have no problems with @escaping.
> 
> func
> iterate(directory inURL: URL?,
>         includingPropertiesForKeys: [URLResourceKey]? = nil,
>         options: FileManager.DirectoryEnumerationOptions = [],
>         errorHandler inErrorHandler: (@escaping (URL, Error) -> Bool)? = nil,
>         iterator inIterator: (@escaping (URL) throws -> ())) rethrows
> {
> }
> 
> I'm not sure why I can't apply @escaping here. Can anyone enlighten me? Thank you.
> 
> --
> Rick Mann
> rmann at latencyzero.com <mailto:rmann at latencyzero.com>
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160913/c5a2981f/attachment.html>


More information about the swift-users mailing list