If a class registers for NSNotificationCenter events of a certain type and another class posts an event of that type, will the code in the receiver execute before (synchronously) or after (asynchro...
h/t Hari!

seen from Malaysia

seen from Malaysia
seen from United States

seen from Canada
seen from China

seen from United States
seen from United States

seen from Singapore

seen from United States
seen from China
seen from China
seen from China

seen from India

seen from Argentina

seen from Malaysia
seen from Italy

seen from Malaysia

seen from Japan
seen from United States

seen from India
If a class registers for NSNotificationCenter events of a certain type and another class posts an event of that type, will the code in the receiver execute before (synchronously) or after (asynchro...
h/t Hari!
NSNotificationCenter
Enjoy! The top two answers are very useful:
http://stackoverflow.com/questions/2191594/send-and-receive-messages-through-nsnotificationcenter-in-objective-c
Fixed Send and receive messages through NSNotificationCenter in Objective-C? #dev #it #asnwer
Fixed Send and receive messages through NSNotificationCenter in Objective-C? #dev #it #asnwer
Send and receive messages through NSNotificationCenter in Objective-C?
I need a simple example program to send and receive a message through NSNotificationCenter in Objective-C ?
Answer: Send and receive messages through NSNotificationCenter in Objective-C?
There is also the possibility of using blocks:
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue]; [[NSNotificationCenter…
View On WordPress
How to: Send and receive messages through NSNotificationCenter in Objective-C?
How to: Send and receive messages through NSNotificationCenter in Objective-C?
Send and receive messages through NSNotificationCenter in Objective-C?
I need a simple example program to send and receive a message through NSNotificationCenter in Objective-C ?
Answer: Send and receive messages through NSNotificationCenter in Objective-C?
@implementation TestClass - (void) dealloc { // If you don't remove yourself as an observer, the Notification Center // will continue to try…
View On WordPress
NSNotificationCenter with blocks considered harmful... unless you use weak references, then it's fine
Drew Crawford published a post entitled NSNotificationCenter with blocks considered harmful yesterday. Upon reading, one might get the impression that using the NSNotificationCenter block API is different in some way then using blocks, well, anywhere else. It isn't.
NSNotificationCenter retains the blocks that you pass to it, and as such, referencing self inside the block will introduce in a nasty retain cycle. This is unfortunate but far from a new revelation; Jim Dovey wrote about this almost exactly two years ago and I got bit pretty hard myself during my earlier days as an iOS developer.
My problem is that Drew's article seems to imply that using blocks with NSNotificationCenter is worse in any way than using any other block that gets retained. Either way, you need to make sure you're not closing over a strong reference to self or suffer the wrath of the resulting retain loop causing some hard-to-debug side effect. The only thing, in my opinion, that makes NSNotificationCenter blocks slightly dicier is that as Drew points out, the normal LLVM warning is for some reason missing in this instance1.
This isn't to say that Drew's article isn't worth reading; it's a great read, and you're almost certain to learn or have something reinforced. Just please know that using blocks at all requires understanding how to use weak references and the consequences of not doing so. I'd recommend reading the article but then following it up with the accompanying Hacker News comment thread, in which Ash Furrow far more eloquently sums up what I've been trying to explain with this post:
There's nothing really magical about this – don't cause retain cycles, everyone knows __block semantics changed with ARC, keep the returned value from the block-based NSNotificationCenter method, etc. Standard stuff.
Probably because unlike most block retain cycles, this one is caused by NSNotificationCenter retaining the block as opposed to self retaining it. ↩︎
Steve Breen tweets:
Tracing all NSNotificationCenter traffic on iOS. Very cool! #iosdev https://t.co/hfV8zyEm1h
— Steve Breen (@steve_breen) October 16, 2013
https://gist.github.com/breeno/7010222