Permalink
Browse files

changed KVO observer matching

  • Loading branch information...
1 parent 6581ab3 commit 19dfef9ba8a1ab50fc2a4fbad7998186f37c8aaa Krzysztof Zablocki committed May 10, 2012
Showing with 46 additions and 1 deletion.
  1. +1 −1 SFObservers/NSObject+SFObservers.m
  2. +45 −0 Sample Project/Sample ProjectTests/Sample_ProjectTests.m
@@ -216,7 +216,7 @@ - (NSUInteger)sf_removeObserver:(id)observer
[observerInfos enumerateObjectsUsingBlock:^void(id innerObj, NSUInteger idx, BOOL *innerStop) {
__SFObserversKVOObserverInfo *info = innerObj;
- if ((!keyPath || [keyPath isEqualToString:info.keyPath]) && (!context || (context == info.context))) {
+ if ((!keyPath || [keyPath isEqualToString:info.keyPath]) && (context == info.context)) {
//! remove this info
[objectsToRemove addObject:innerObj];
@@ -96,6 +96,23 @@ - (void)testKVOOverObserving2
#endif
}
+- (void)testKVOOverObserving3
+{
+#if SF_OBSERVERS_ALLOW_MULTIPLE_REGISTRATIONS
+
+ [observedObject addObserver:observer forKeyPath:@"description" options:NSKeyValueObservingOptionNew context:AH_BRIDGE(self)];
+ [observedObject addObserver:observer forKeyPath:@"description" options:NSKeyValueObservingOptionNew context:AH_BRIDGE(self)];
+ [observedObject addObserver:observer forKeyPath:@"description" options:NSKeyValueObservingOptionNew context:AH_BRIDGE(self)];
+
+ [observedObject removeObserver:observer forKeyPath:@"description" context:nil];
+ [observedObject removeObserver:observer forKeyPath:@"description" context:AH_BRIDGE(self)];
+ [observedObject removeObserver:observer forKeyPath:@"description" context:AH_BRIDGE(self)];
+
+ AH_RELEASE(observer), observer = nil;
+ AH_RELEASE(observedObject), observedObject = nil;
+#endif
+}
+
- (void)testKVONotBreakingArray
{
@@ -215,4 +232,32 @@ - (void)testNotificationOverObserving2
}
#endif
}
+
+- (void)testNotificationOverObserving3
+{
+#if SF_OBSERVERS_ALLOW_MULTIPLE_REGISTRATIONS
+
+ @try {
+ static NSString *fakeNotification = @"FakeNotification";
+ [[NSNotificationCenter defaultCenter] addObserver:observer selector:@selector(unsupportedSelector) name:fakeNotification object:self];
+ [[NSNotificationCenter defaultCenter] addObserver:observer selector:@selector(unsupportedSelector) name:fakeNotification object:self];
+ [[NSNotificationCenter defaultCenter] addObserver:observer selector:@selector(unsupportedSelector) name:nil object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:observer selector:@selector(unsupportedSelector) name:nil object:nil];
+
+ [[NSNotificationCenter defaultCenter] removeObserver:observer name:nil object:nil];
+ [[NSNotificationCenter defaultCenter] removeObserver:observer name:fakeNotification object:nil];
+ [[NSNotificationCenter defaultCenter] removeObserver:observer name:fakeNotification object:self];
+
+ AH_RELEASE(observer), observer = nil;
+ AH_RELEASE(observedObject), observedObject = nil;
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:fakeNotification object:self];
+ [[NSNotificationCenter defaultCenter] postNotificationName:fakeNotification object:nil];
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"OtherNotification" object:self];
+ }
+ @catch (NSException *exception1) {
+ STFail(@"Exception %@", exception1);
+ }
+#endif
+}
@end

0 comments on commit 19dfef9

Please sign in to comment.