• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ^Block statement considered harmful for callbacks?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ^Block statement considered harmful for callbacks?


  • Subject: Re: ^Block statement considered harmful for callbacks?
  • From: Lee Ann Rucker <email@hidden>
  • Date: Thu, 25 Apr 2013 09:54:08 -0700 (PDT)
  • Thread-topic: ^Block statement considered harmful for callbacks?

> My point remains: blocks are dangerous and there is no easy way to
> ensure they are safe. You can't avoid referencing "self" in blocks,
> because it is the very point of almost every callback block. So you
> have to every time to remind yourself to jump through hoops to avoid
> the retain cycles. Nah.


Yes you can.

MyWeakRef *weakRef = [MyWeakRef weakRefFromObject:self];

^() = {
  Foo *wself = [weakRef originalObject];
  // wself may be nil, that's cool because we only want to doStuff if 'self' is still around.
  [wself doStuff];
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: ^Block statement considered harmful for callbacks?
      • From: Jens Alfke <email@hidden>
    • Re: ^Block statement considered harmful for callbacks?
      • From: Torsten Curdt <email@hidden>
References: 
 >^Block statement considered harmful for callbacks? (From: Oleg Krupnov <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Tom Davie <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Oleg Krupnov <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Tom Davie <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Diederik Meijer | Ten Horses <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Tom Davie <email@hidden>)
 >Re: ^Block statement considered harmful for callbacks? (From: Oleg Krupnov <email@hidden>)

  • Prev by Date: Re: sandboxd deny hid-control weirdness
  • Next by Date: Re: Temporarily disabling autosave
  • Previous by thread: Re: ^Block statement considered harmful for callbacks?
  • Next by thread: Re: ^Block statement considered harmful for callbacks?
  • Index(es):
    • Date
    • Thread