mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-03-25 09:25:47 +00:00
36 lines
1.2 KiB
Objective-C
36 lines
1.2 KiB
Objective-C
//
|
|
// NotificationToSelectorMap.m
|
|
// Blog
|
|
//
|
|
// Created by Sami Samhuri on 2015-06-29.
|
|
// Copyright © 2015 Guru Logic Inc. All rights reserved.
|
|
//
|
|
|
|
#import "NotificationToSelectorMap.h"
|
|
|
|
@implementation NotificationToSelectorMap
|
|
|
|
- (instancetype)initWithNotificationMap:(nonnull NSDictionary *)notificationMap {
|
|
self = [super init];
|
|
if (self) {
|
|
_notificationNameToSelectorNameMap = notificationMap;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)addObserver:(NSObject *)observer {
|
|
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
|
for (NSString *notificationName in self.notificationNameToSelectorNameMap.allKeys) {
|
|
NSString *selectorName = self.notificationNameToSelectorNameMap[notificationName];
|
|
[notificationCenter addObserver:observer selector:NSSelectorFromString(selectorName) name:notificationName object:nil];
|
|
}
|
|
}
|
|
|
|
- (void)removeObserver:(NSObject *)observer {
|
|
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
|
for (NSString *notificationName in self.notificationNameToSelectorNameMap.allKeys) {
|
|
[notificationCenter removeObserver:observer name:notificationName object:nil];
|
|
}
|
|
}
|
|
|
|
@end
|