Last active
August 29, 2015 14:15
-
-
Save Kozlov-V/0aba155e8c09ac99faf9 to your computer and use it in GitHub Desktop.
observers.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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