From: Knud H. M. <knu...@de...> - 2008-02-27 18:21:14
|
Hi all, I'm trying to implement something with dependent keys in core data. I try to follow the documentation at: http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/DependentKeys.html Basically, I implement a subclass of NSManagedObject which includes a custom method "fullName" for the dependent key (fullname depends of "firstName" and "lastName"). To make it work, I need to call setKeys:triggerChangeNotificationsForDependentKey: on my subclass. I implemented this in ObjC, and it works just fine: @implementation DKTEntity + (void)initialize { [self setKeys: [NSArray arrayWithObjects: @"firstName", @"lastName", nil] triggerChangeNotificationsForDependentKey:@"fullName"]; } - (NSString *)fullName { return [NSString stringWithFormat: @"%@ %@", [self firstName], [self lastName]]; } @end Now I tried to do the same in RubyCocoa, like this: class DKTEntity < OSX::NSManagedObject def DKTEntity.initialize DKTEntity .setKeys_triggerChangeNotificationsForDependentKey(["firstName", "lastName"], "fullName") end def fullName # this is the definition of the dependent key fullName return "#{firstName} #{lastName}" end end However, this results in an ugly crash upon startup: 2008-02-27 17:35:41.473 DependentKeysTest[1178:10b] AppDelegate#rbValueForKey: RuntimeError: Ruby object `OSX::DKTEntity_DKTEntity_' doesn't respond to the ObjC selector `initialize', the method either doesn't exist or is private I'm new to RubyCocoa (and Ruby) and have no real clue as to what the problem is here? Is it the way I override the initialize class method? I tried other idioms, but the error remains the same. I also tried to call setKeys... outside any initialize method, like so: class DKTEntity < OSX::NSManagedObject DKTEntity .setKeys_triggerChangeNotificationsForDependentKey(["firstName", "lastName"], "fullName") ... end This doesn't crash, but unfortunately doesn't seem to have any effect at all (fullName will remain unspecified). If you want to play around with the code, look here: ObjC version: http://sw.deri.org/~knud/stuff/DependentKeyTestObjC.zip Ruby version: http://sw.deri.org/~knud/stuff/DependentKeysTest.zip Any help appreciated! Cheers, Knud ------------------------------------------------- Knud Möller, MA +353 - 91 - 495086 Smile Group: http://smile.deri.ie Digital Enterprise Research Institute National University of Ireland, Galway Institiúid Taighde na Fiontraíochta Digití Ollscoil na hÉireann, Gaillimh |