Wanted: syntactic sugar for [weak self] callbacks

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@CircleW.org

Hi Kurt,

I believe that this is currently being discussed in "the bind thread <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160201/008649.html&gt;&quot;\.

Félix

···

Le 1 févr. 2016 à 18:40:18, Kurt Werle via swift-evolution <swift-evolution@swift.org> a écrit :

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@CircleW.org
http://www.CircleW.org/kurt/ <http://www.circlew.org/kurt/&gt;
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

The bind thread is certainly similar, and if something like that was
adapted, I'd like to see [bind self] do the same kind of thing in closure
declarations that I'm proposing [firm self] does - but the very odd
syntax for closure parameters tastes pretty different to me than a lot of
the rest of the language. I don't think it's unreasonable to discuss them
separately.

Thanks,
Kurt

···

On Tue, Feb 2, 2016 at 12:02 AM, Félix Cloutier <felixcca@yahoo.ca> wrote:

Hi Kurt,

I believe that this is currently being discussed in "the bind thread
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160201/008649.html&gt;
".

Félix

Le 1 févr. 2016 à 18:40:18, Kurt Werle via swift-evolution < > swift-evolution@swift.org> a écrit :

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@CircleW.org <kurt@circlew.org>
Welcome to circlew.org <Welcome to circlew.org;
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
kurt@CircleW.org
http://www.CircleW.org/kurt/