From: Jon B. <jo...@gm...> - 2007-06-26 16:39:59
|
Probably best to look @ source for the 2 methods (see snippet below, found in oc_import), basically it will add the needed binding methods for you automagically. Im not sure (without seeing your code) if it should go in something higher up (AppController) or MyDocument. And the key itself seems to be hooking them up correctly in Interface Builder (and using the right key path). Im sure there is something in the examples folder which has this already, need to look @ what key paths are being used and where kvc is declared. --snip-- def kvc_writer(*args) args.flatten.each do |key| setter = key.to_s + '=' attr_writer(key) unless method_defined?(setter) alias_method kvc_internal_setter(key), setter self.class_eval <<-EOE_KVC_WRITER,__FILE__,__LINE__+1 def #{kvc_setter_wrapper(key)}(value) willChangeValueForKey('#{key.to_s}') send('#{kvc_internal_setter(key)}', value) didChangeValueForKey('#{key.to_s}') end EOE_KVC_WRITER alias_method setter, kvc_setter_wrapper(key) end end def kvc_accessor(*args) kvc_reader(*args) kvc_writer(*args) end def kvc_reader(*args) attr_reader(*args) end - Jon On Jun 26, 2007, at 12:12 PM, Tim Perrett wrote: > Hey Jon > > Thanks for getting back to me. So if i add in the > > kvc_accessor :server > > declaration in my MyDocument.rb file, how would I access this as? As > my document is obviously already instantiated I wouldn't want to > create a new object as that would cause error. Unless the second > object I create subclass from NSManagedObject and I bind it within IB > to set the managedObjectContext to be the main object controller? > Perhaps I should be looking for an answer to my problem using > bindings rather than straight code as I know it. When you write > kvc_accessor what is that actually doing in the background? > > Thanks > > Tim > > > > > On 26 Jun 2007, at 13:57, Jon Baer wrote: > >> From my understanding (ala bindings), you would make the @server >> object a kvc_accessor and access it via a key path. >> >> server.serverAddress >> >> Of course Im just guessing but Ive recently had to do a multi-level >> situation where I needed access in .nib for something else and went >> through a few more binding tutorials to understand what was >> happening. Im @ the point where Id like to dynamically setup all >> bindings @ runtime. >> >> - Jon >> >> On Jun 26, 2007, at 4:37 AM, Tim Perrett wrote: >> >>> Hey all >>> >>> I have managed to fix my core data problems which i previously >>> posted >>> about (yay) but I am now working with my entitys and due to some >>> lack >>> in my understanding struggling to actually access the data >>> programatically. >>> >>> I can access table attributes in MyDocument.rb with something like >>> this: >>> >>> @server.valueForKey('serverAddress') >>> >>> But what I want to do is access those values from another class, how >>> would I do this? I have read about KVC accessors and things but are >>> they even what I need? I would like this second class to handle all >>> the task processing and the ib_outlets and so on. This would mean >>> instantiating it in the nib in order to link the outlets, which >>> brings me back round to how can I then access items on my other >>> object? >>> >>> Thanks >>> >>> Tim >>> >>> -------------------------------------------------------------------- >>> - >>> - >>> --- >>> This SF.net email is sponsored by DB2 Express >>> Download DB2 Express C - the FREE version of DB2 express and take >>> control of your XML. No limits. Just data. Click to get it now. >>> http://sourceforge.net/powerbar/db2/ >>> _______________________________________________ >>> Rubycocoa-talk mailing list >>> Rub...@li... >>> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >> >> >> --------------------------------------------------------------------- >> - >> --- >> This SF.net email is sponsored by DB2 Express >> Download DB2 Express C - the FREE version of DB2 express and take >> control of your XML. No limits. Just data. Click to get it now. >> http://sourceforge.net/powerbar/db2/ >> _______________________________________________ >> Rubycocoa-talk mailing list >> Rub...@li... >> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >> > > > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk |