Skip to content

Comment on NSNotificationCenter with blocks considered harmfulparent

Comments

Using blocks is the one bit of Objective-C that still reminds me of the old MRR style. Just like with retain/release/autorelease, it's one thing understanding the pattern, it's another ensuring that your entire program conforms to it. Anywhere that you capture nontrivial objects is a possible failure point.

ReactiveCocoa has some nice patterns for avoiding block callbacks altogether. Eg:

   [myTarget rac_liftSelector:@selector(receiveCallback:) withSignals:mySignal, nil];
will capture a weak reference to the target, invoke the callback whenever 1 or more events fire and automatically unsubscribe when the target deallocates.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.