MacRuby KVO array ERROR?

A

Andras Zalavari

Hi! I'm new To MacRuby, all day I was trying to find what causes the
error in my Code.

I have a 'Scene' class with an attribute 'nodes', which is an array. I
have set up kvo methodes for the array
I have an Observer object, who observes the scene.nodes property. The
observer's options is
'NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld'

when I add a node to the scene with scene.addNode( new object )
everything is working.
but when I try to remove a node I got an error:

NSInvalidArgumentException: -[NSCFArray countForObject:]: unrecognized
selector sent to instance 0x1b4c210

I only got this error, when I have the NYKeyValueObserbingOptionOld. But
I would really need it.

I assume, the somewhere MacRuby switch the class of the supplied NSSet
containing the objects involved in the change (in the manual KVO call:
willChangeValueForKey: ... withSetMutation... objects:(NSSet) )

please help!
Thanks

here is the appropiate code:

OBSERVER.rb

class ConnectionViewController
attr_accessor:scene,:selection
attr_accessor:view
def initialize
puts 'ConnectionViewController=>initialize'
NSBundle.loadNibNamed("ConnectionViewController", owner:self)
addObserver(self,
forKeyPath:'scene.nodes',
options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld,
context:nil)

node=Node.new
scene.addNode(node)
scene.removeNode(node)
end
def observeValueForKeyPath(keyPath,
ofObject:eek:bject,
change:change,
context:context)
puts self,' observed:',change,' keyPath:',keyPath
case change['kind']
when NSKeyValueChangeInsertion then
puts 'insertion: '+change['new'].allObjects.to_s

when NSKeyValueChangeRemoval then
puts 'removal: '+change['old'].allObjects.to_s
end
end
end

SCENE.m

#import "Scene.h"


@implementation Scene
@synthesize title;
@synthesize nodes,wires;
- (id) init
{
self = [super init];
if (self != nil) {
title=@"untitled scene";
nodes=[NSMutableArray new];
wires=[NSMutableArray new];
NSLog(@"%@=>init",self);
}
return self;
}

//PROPERTY METHODES
#pragma mark PROPERTY METHODES
-(Node*)addNode:(Node*)node{
NSLog(@"Scene->addNode:%@",node);
NSSet *nodeSet=[NSSet setWithObject:node];
[self willChangeValueForKey:mad:"nodes"
withSetMutation:NSKeyValueUnionSetMutation usingObjects:nodeSet];
[nodes addObject:node];
node.scene=self;
[self didChangeValueForKey:mad:"nodes"
withSetMutation:NSKeyValueUnionSetMutation usingObjects:nodeSet];
return node;
}
-(void)removeNode:(Node*)node{
NSSet *nodeSet=[NSSet setWithObjects:node,nil];
NSLog(@"Scene->removeNode %@",node);
[self willChangeValueForKey:mad:"nodes"
withSetMutation:NSKeyValueMinusSetMutation usingObjects:nodeSet];
[nodes removeObject:node];
[self didChangeValueForKey:mad:"nodes"
withSetMutation:NSKeyValueMinusSetMutation usingObjects:nodeSet];
}
@end

Attachments:
http://www.ruby-forum.com/attachment/5372/RubyLine.zip
 
R

Ryan Davis

Hi! I'm new To MacRuby, all day I was trying to find what causes the
error in my Code.

Please take this to the MacRuby list. They're very responsive and helpful.=20=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top