+ (BOOL)automaticallyNotifiesObserversOf<Key> support.

This commit is contained in:
Alexander Ljungberg
2012-03-27 23:42:17 +01:00
parent 25676b4460
commit 271b935ba2
2 changed files with 32 additions and 0 deletions
+6
View File
@@ -71,6 +71,12 @@
+ (BOOL)automaticallyNotifiesObserversForKey:(CPString)aKey
{
var capitalizedKey = aKey.charAt(0).toUpperCase() + aKey.substring(1),
selector = "automaticallyNotifiesObserversOf" + capitalizedKey;
if ([[self class] respondsToSelector:selector])
return objj_msgSend([self class], selector);
return YES;
}
@@ -193,11 +193,37 @@
notSame:class_getInstanceMethod([object class], removeSelector)];
}
- (void)testAutomaticallyNotifiesObserversOf
{
var test = [ObservingTester new];
[test addObserver:self forKeyPath:@"cheese" options:0 context:nil];
[test addObserver:self forKeyPath:@"astronaut" options:0 context:nil];
// Cheese shouldn't have been affected.
[test setCheese:@"changed cheese"];
[self assert:@"cheese" equals:_lastKeyPath]
[self assert:test equals:_lastObject];
// Cheese shouldn't have been affected.
[test setAstronaut:@"Armstrong"];
// Nothing should have been observed because we don't automatically notify
// and we didn't call will/didChange.
[self assert:@"cheese" equals:_lastKeyPath message:"no observation when automatically notifies is off"];
[self assert:test equals:_lastObject];
}
@end
@implementation ObservingTester : CPObject
{
id cheese;
id astronaut @accessors;
}
+ (BOOL)automaticallyNotifiesObserversOfAstronaut
{
return NO;
}
+ (id)testerWithCheese:(id)aCheese