TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by airin.
I aimed at the implementation of Node.js EventEmmiter.
and KVO.
It was inspired by the following products.
Requires iOS 5.0 or later, and uses ARC.
object A (On)
[[self class] arn_emitterOn:@"test" owner:self needMainThreadCall:YES callbackBlock:^(id resultObject){
// called MianThread
NSLog(@"A");
}];
object B (On)
[[self class] arn_emitterOn:@"test" owner:self needMainThreadCall:NO callbackBlock:^(id resultObject){
// called not MianThread
NSLog(@"B");
}];
object C (Emit)
[[self class] arn_emitterEmit:@"test" resultObject:nil];
// called objectA emitterOn
// called objectB emitterOn
[[self class] arn_emitterEmit:@"test" resultObject:nil];
// called objectA emitterOn
// called objectB emitterOn
object A (On)
[[self class] arn_emitterOn:@"test" owner:self needMainThreadCall:YES callbackBlock:^(id resultObject){
// called MianThread
NSLog(@"A");
}];
object B (Once)
[[self class] arn_emitterOnce:@"test" owner:self needMainThreadCall:NO callbackBlock:^(id resultObject){
// called not MianThread
NSLog(@"B");
}];
object C (Emit)
[[self class] arn_emitterEmit:@"test" resultObject:nil];
// called objectA emitterOn
// called objectB emitterOnce
[[self class] arn_emitterEmit:@"test" resultObject:nil];
// called objectA emitterOn
object A (On)
[[self class] arn_emitterOn:@"test" owner:self needMainThreadCall:YES callbackBlock:^(id resultObject){
// called MianThread
NSLog(@"A");
}];
object B (Off)
[[self class] arn_emitterOnce:@"test" owner:self needMainThreadCall:NO callbackBlock:^(id resultObject){
// called not MianThread
NSLog(@"B");
[self class] arn_emitterOff:@"test" owner:self];
}];
object C (Emit)
[[self class] arn_emitterEmit:@"test" resultObject:nil];
// called objectA emitterOn
// called objectB emitterOn
[[self class] arn_emitterEmit:@"test" resultObject:nil];
// called objectA emitterOn
Attention!!
Use exchange Implementations by the following
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
KVO
MyObject *objA = MyObject.new;
MyObject *objB = MyObject.new;
objA.count = 0;
objB.count = 0;
[objA arn_emitterObserve:objB keyPath:@"count" isOnce:NO needMainThreadCall:NO callbackBlock:^(id resutObject) {
objA.count++;
}];
objB.count++;
// call arn_emitterObserve
objB.count++;
// call arn_emitterObserve
// objA.count == 2
The source code is distributed under the nonviral MIT License.
It's the simplest most permissive license available.
Node.js界隈で広く使われているEventEmitterオブジェクトをObjective-Cで実装したものです。
(Node.jsのEventEmitterオブジェクトと同一の機能を有しているわけではありません)