From: Pierce T. W. I. <pi...@tw...> - 2007-11-14 17:28:41
|
On Nov 11, 2007, at 8:28 AM, Jacob Wallstr=F6m wrote: > Summary of post: I can't get ruby subclasses of NSMangedObject to work > if they have their own attribute implementations with RubyCocoa on > Leopard. I desperately need this to work, have anybody solved this > problem? > --- > > I'm having major problems with porting my application to Leopard. The > problem is that my application relies on ruby subclasses of > NSManagedObject which contains methods implementing the core data > attributes. The default attribute implementation provided by Core Data > is not enough since changes in an attribute can trigger changes in > other attributes etc. Since I have a UI that uses bindings, a lot of > the access to my entities is happening from Obj-C and I need these > calls to go through the ruby methods of my entities. > > I got this working quite well with RC 0.12.0 on Tiger. By overriding > setValue:forKey: and having it check for a ruby set-method before > passing the call on to the setValue:forKey: method in NSManagedObject > I could get all access from Obj-C to the attributes to pass trough the > ruby methods which was what I wanted. I also used KVO-observing to get > notified of changes in certain attributes. I had problems with this as well on Tiger, but my solution was to use =20= MOGenerator to make Obj-C base classes for all of my data objects with =20= the accessors on that side, then override them from ruby if I needed =20 too. That also had the advantage of being faster because: def value willReadValueForKey("value") result=3D @value didReadValueForKey("value") end Had several bridge crossings to deal with, especially when used with =20 bindings, so that sped up anything that just needed a simple accessor. You could make your own subclass of NSManagedObject and override the =20 method that handles "unhandled keys" because on Tiger at least, that's =20= actually how NSManagedObject works. setValue: forKey: falls through to =20= being "unhandled" and then NSManagedObject uses its default =20 implementation. For Leopard, I'm not sure how much help I can be because my app broke =20= with weird Core Data errors. So I upgraded to trunk thinking it might =20= be issues with the last version I was using vs. release, but now it =20 crashes inside rubycocoa instead. So now every morning I do: svn update ruby install.rb setup sudo install.rb install With my fingers crossed but I'm getting: 2007-11-14 10:24:19.723 Frictionless[10512:10b] LIBFFI : arg[5] -> =20 ffi_type 0xa04b4034 2007-11-14 10:24:19.723 Frictionless[10512:10b] OVMIX : Registered =20 Ruby method by selector =20 'outlineView:willDisplayCell:forTableColumn:item:' types =20 'v24@0:4@8@12@16@20' /Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/=20 oc_import.rb:266: [BUG] Bus Error ruby 1.8.6 (2007-06-07) [universal-darwin9.0] Abort trap My apps is open source from http://www.twinforces.com/frictionless/ =20= though if you want to check it out. Pierce |