Skip to content

Instantly share code, notes, and snippets.

@Kozlov-V
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kozlov-V/0aba155e8c09ac99faf9 to your computer and use it in GitHub Desktop.
Save Kozlov-V/0aba155e8c09ac99faf9 to your computer and use it in GitHub Desktop.
observers.m
FancyHotSpot *hotSpotA;
FancyHotSpot *hotSpotB;
// notifications from hotSpotA should call hotSpotATouched:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hotSpotATouched:) name:@"HotSpotTouched"
object:hotSpotA]; // only notifications from hotSpotA will be received
// notifications from hotSpotB should call hotSpotBTouched:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hotSpotBTouched:) name:@"HotSpotTouched"
object:hotSpotB]; // only notifications from hotSpotB will be received
// notifications from all objects should call anyHotSpotTouched:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(anyHotSpotTouched:) name:@"HotSpotTouched"
object:nil]; // nil == “any object”, so all notifications with the name “HotSpotTouched” will be received
- (void)hotSpotATouched:(NSNotification *)n {
// only gets notification of hot spot A
}
- (void)hotSpotBTouched:(NSNotification *)n {
// only gets notification of hot spot B
}
- (void)anyHotSpotTouched:(NSNotification *)n {
// catches all notifications
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment