3

my code is crashing at:

[[NSNotificationCenter defaultCenter] postNotificationName:kgotNotification object:dictionary];

my assumption is that I am posting a notification before the observer is added.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getItems:) name:kgotNotification object:nil];

is there a way to check for the list of active observers before posting a notification?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
shebelaw
  • 3,992
  • 6
  • 35
  • 48

1 Answers1

2

You should do it like this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getItems:) name:kgotNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:kgotNotification object:self userInfo:dictionary];

Then your getItems Method:

-(void)getItems:(NSNotification* )note
{
    NSLog(@"UserInfo: %@", note.userInfo);
}
jbouaziz
  • 1,484
  • 1
  • 12
  • 24
iCode
  • 1,456
  • 1
  • 15
  • 26