From: Jonathan P. <jp...@dc...> - 2005-11-03 23:13:48
|
On 3 Nov 2005, at 21:31, Rupert Barrow wrote: > I have got to chapter 3 (creating the custome Employee class) : > this works with Employee.rb, I have even got fullNameAndID working, > dynamically computed from firstName and lastName, and displayed in > the GUI. > However, I do not seem to be able to connect firstName in the GUI > with the model in Employee.rb; ditto for lastName. This is my > Employee class : I'm not entirely sure from your description what the problem you're having is. However, I do notice a problem with your code that may be related: > class Employee < OSX::NSManagedObject > include OSX > > attr_accessor :firstName > attr_accessor :lastName > > kvc_accessor :lastName, :firstName > kvc_depends_on([ :lastName, :firstName], :fullNameAndID) > > def initialize > @firstName = "MyFirst" > @lastName = "MyLast" > end > [Let me say first that I've not used Core Data yet, so this is my understanding from glancing over the documentation. Please correct any misunderstanding!] Since you're using Core Data, all the data members of the class are already managed for you. Therefore, you should not define firstName and lastName as accessors, nor should you use ruby @firstName/ @lastName variables. Instead, just access firstName etc as if it were already defined as an accessor (or perhaps you need to use setValue:forKey: and valueForKey:). RubyCocoa will forward the call through to Objective C, where Core Data will handle the request for you. Hope that is of some help, Jonathan |