Self-regulation pointer
static void *foo = &foo;
is just a method of creating a unique pointer at compile time .
In this AVSimpleEditoriOS example , these pointers are later used as the context parameter for
[self addObserver:self forKeyPath:@"player.currentItem.status" options:NSKeyValueObservingOptionNew context:AVSEPlayerItemStatusContext];
and
[self addObserver:self forKeyPath:@"playerLayer.readyForDisplay" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:AVSEPlayerLayerReadyForDisplay];
The actual value of the context parameter does not matter at all, it's just some unique value that is passed to
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (context == AVSEPlayerItemStatusContext) { // Notification for @"player.currentItem.status" // ... } else if (context == AVSEPlayerLayerReadyForDisplay) { // Notification for @"playerLayer.readyForDisplay" // ... } else { // Something else, pass to superclass: [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } }
(Alternatively, you can check the keyPath parameter in observeValueForKeyPath .) See @Bavarious's comment below why unique context pointers are generally preferred for key strings.
source share