at_yasu's blog

ロード的なことを

Notification

使い方、書いていなかったのでメモ書き

まず、受け取り側。addObserver:selector:name:objectで受け取る準備をする。

- (void) catcher
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(loadAPI:)
                                                 name:NCVIDEO_GET_VIDEOREF_NOTIFICATION
                                               object:nil];
}

- (void) loadAPI:(NSNotification*)notification
{
// something  code..
}

投げ手。ワッパーメソッド _sendNotification:を作って楽しているけど、結局はNSNotification の postNotificationName:object:userInfoで通知を投げている。

#pragma mark notification
- (void) _sendNotification: (NSString *)type
                   message:(NSObject *)message
{
	[[NSNotificationCenter defaultCenter] postNotificationName:type
                                                        object:message
                                                      userInfo:nil];
}

- (void) _sendNotification: (NSString *)type
{
    [self _sendNotification:type
                    message:self];
}

- (void) sender
{   
    [self _sendNotification:NCVIDEO_GET_VIDEOREF_NOTIFICATION
                    message:file];
}