[swift-evolution] Wanted: syntactic sugar for [weak self] callbacks

Kurt Werle kurt at circlew.org
Mon Feb 1 17:40:18 CST 2016


The pattern

someObject.callBack() { [weak self] in
  if let me = self {
    me.doSomething()
    ...
  }
}

and friends (guard, etc) are pretty common.  I'd love to have some sugar
for that - maybe "firm"

someObject.callBack() { [firm self] in
  self.doSomething()
  ...
}

where firm guarantees that the named variable[s] won't be nil - if they
are, the block is skipped.

I think this would make the language easier to use (skipping the
complexities/distinction between weak/unowned), more concise, and generally
more pleasant.

Thoughts?

Thanks,
Kurt
-- 
kurt at CircleW.org
http://www.CircleW.org/kurt/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160201/082bd668/attachment.html>


More information about the swift-evolution mailing list