ios - Are NSNotificationCenter events received synchronously or asynchronously? -


if class registers nsnotificationcenter events of type , class posts event of type, code in receiver execute before (synchronously) or after (asynchronously) posting class continues?

- (void)poster {     [[nsnotificationcenter defaultcenter]         postnotificationwithname:@"myevent"         object:nil];     nslog(@"hello poster"); }  - (void)receiver {     [[nsnotificationcenter defaultcenter]         addobserver:self         selector:@selector:(myselector)         name:@"myevent"         object:nil]; }  - (void) myselector:(nsnotification *) notification {     nslog(@"hello receiver"); } 

in code example above, "hello receiver" printed before or after "hello caller"?

as stated in documentation nsnotificationcenter nsnotificationcenter class reference notifications posted synchronously.

a notification center delivers notifications observers synchronously. in other words, postnotification: methods not return until observers have received , processed notification. send notifications asynchronously use nsnotificationqueue.

in multithreaded application, notifications delivered in thread in notification posted, may not same thread in observer registered itself.

hope helps you.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -