Wednesday, August 4, 2021

Swift “guard” Capture Specifier Pitch

Cal Stephens (tweet):

guard captures behave like weak captures (e.g. guard captures do not retain the captured value), but the closure body is only executed if the captured objects still exist.

[…]

As of SE-0269, strong and unowned captures of self enable implicit self calls within the body of escaping closures. This is not straightforward to support for weak closures in the general case, and was intentionally excluded from SE-0269.

[…]

guard let value = value else { return } is quite a bit of boilerplate in this context.

Previously:

Comments RSS · Twitter

Leave a Comment