Skip to content

Instantly share code, notes, and snippets.

@natemartinsf
Created May 28, 2011 03:45
Show Gist options
  • Save natemartinsf/996575 to your computer and use it in GitHub Desktop.
Save natemartinsf/996575 to your computer and use it in GitHub Desktop.
KVO method firing twice
//Output:
/*
Frameworks/Debug/Objective-J/Objective-J.js:4322011-05-27 20:42:05.282 Cappuccino [info]: observed: attributeController.arrangedObjects change: {
CPKeyValueChangeKindKey = "1"
CPKeyValueChangeOldKey = "newArrayObject"
CPKeyValueChangeNewKey = "newArrayObject"
}
Frameworks/Debug/Objective-J/Objective-J.js:4322011-05-27 20:42:05.284 Cappuccino [info]: observed: attributeController.arrangedObjects change: {
CPKeyValueChangeKindKey = "1"
CPKeyValueChangeOldKey = "newArrayObject"
CPKeyValueChangeNewKey = "newArrayObject"
}
*/
//AppController.j:
/*
* AppController.j
* KVOTest
*/
@import <Foundation/CPObject.j>
@import "ParentObject.j"
@implementation AppController : CPObject
{
CPWindow theWindow; //this "outlet" is connected automatically by the Cib
ParentObject testObject @accessors;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// This is called when the application is done loading.
testObject = [[ParentObject alloc] init];
[testObject addObserver:self
forKeyPath:@"attributeController.arrangedObjects"
options:(CPKeyValueObservingOptionNew)
context:NULL];
[[testObject attributeController] addObject:@"newArrayObject"];
}
- (void)awakeFromCib
{
// This is called when the cib is done loading.
// You can implement this method on any object instantiated from a Cib.
// It's a useful hook for setting up current UI values, and other things.
// In this case, we want the window from Cib to become our full browser window
[theWindow setFullPlatformWindow:YES];
}
- (void)observeValueForKeyPath:(CPString)keyPath ofObject:(id)object change:(CPDictionary)change context:(void )context
{
CPLog(@"observed: "+keyPath+" change: "+change);
}
@end
//ParentObject.j:
@import <Foundation/CPObject.j>
@implementation ParentObject : CPObject
{
CPMutableArray attributeArray @accessors;
CPArrayController attributeController @accessors;
}
-(id)init
{
self = [super init];
if(self)
{
attributeArray = [[CPMutableArray alloc] init];
attributeController = [[CPArrayController alloc] init];
[attributeController setContent:attributeArray];
}
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment