From: Rich W. <rw...@gm...> - 2008-01-03 07:28:17
|
Hi, I'm working on a RubyCocoa Core Data project. In that project, I'm trying to subclass NSManagedObject to return specific values for the count attribute. Count otherwise behaves like any other Core Data attribute. The following Objective C code works fine. It correctly returns the number of posts associated with the posts relationship. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #import <Cocoa/Cocoa.h> @interface ObjCManagedFeed : NSManagedObject { } -(int)count; @end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #import "ObjCManagedFeed.h" @implementation ObjCManagedFeed -(int)count { id posts = [self valueForKey:@"posts"]; NSArray * all = [posts allObjects]; return [all count]; } @end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ However, when I try to convert this to Ruby, the count() method is never called. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require 'osx/cocoa' class ManagedFeed < OSX::NSManagedObject def count() puts "*** This never gets called ***" posts = valueForKey_("posts") posts.allObjects.size end end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I don't understand why; though it might be a bad interaction between Core Data's bindings and RubyCocoa's wrappers. I also wonder if this has anything to do with my last, KVO question. If anyone can explain this to me, I'd be grateful. Thanks. -Rich- |