-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandRegistry.m
More file actions
48 lines (38 loc) · 1001 Bytes
/
CommandRegistry.m
File metadata and controls
48 lines (38 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// CommandRegistry.m
// Curate
//
// Created by Constantine Karlis on 20/04/12.
// Copyright (c) 2012 Constantine Karlis. All rights reserved.
//
#import "CommandRegistry.h"
@implementation CommandRegistry
{
NSMutableDictionary* _registry;
}
- (id)init
{
self = [super init];
if (self)
{
_registry = [[NSMutableDictionary alloc] init];
}
return self;
}
-(void)addCommand:(Class)commandClass forKey:(NSString*)key
{
[_registry setObject:commandClass forKey:key];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fireCommand:) name:key object:nil];
}
-(void)removeCommand:(Class)commandClass forKey:(NSString*)key
{
[_registry removeObjectForKey:key];
[[NSNotificationCenter defaultCenter] removeObserver:self name:key object:nil];
}
-(void)fireCommand:(NSNotification*)noti
{
Class c = [_registry objectForKey:noti.name];
NSObject<Command>* bcc = [[c alloc] init];
[bcc execute:noti];
}
@end