From: Laurent S. <lsa...@ap...> - 2007-08-04 18:25:49
|
On Aug 4, 2007, at 6:39 PM, Eloy Duran wrote: > Yes! It doesn't crash anymore and the row is added to the tableview. I > haven't had time yet to extensively play with this, but I guess it > will be ok. > > Thanks :) Okay, this is a bug in Foundation's BridgeSupport, that doesn't provide metadata for the NSCopying protocol. Fortunately this is a very edge case, but I will try to fix it the soonest possible. > So just for reference, the code I have working now is: > > def copyWithZone(zone) > copy = self.class.allocWithZone(zone).init > self.instance_variables.each do |iv| > copy.instance_variable_set iv, self.instance_variable_get(iv) > end > return copy > end > objc_method :copyWithZone, "@@:^v" > > I have no idea if this is a good idea, but could this be included in > something like oc_attachments or is that a bad idea? Mmh, I don't think that this is a good idea. Not everyone wants to copy all instance variables for example upon every copy (some would prefer to call the original setters which may encapsulate some ObjC logic). The bug behind this should be fixed though. The user should not have to call objc_method. Laurent > On 8/4/07, Laurent Sansonetti <lsa...@ap...> wrote: >> Okay, that's because your cell's object value is a NSObject class >> that >> doesn't implement copyWithZone. From your first message I see that >> you >> got a crash when trying to implement it. >> >> Can you try to call: >> >> objc_method :copyWithZone, ''@@:^v" >> >> inside your Download class? >> >> Thanks, >> Laurent >> >> On Aug 4, 2007, at 6:18 PM, Eloy Duran wrote: >> >>> Yes, that's true. However the problem is not with the NSCell >>> subclass >>> (DownloadCell) but with the NSObject subclass (Download) that holds >>> the values for the cell. >>> >>> If I don't implement the copyWithZone method it exits with a method >>> not found error: >>> 2007-08-04 18:15:29.644 HellaNZB[3861] *** -[Download >>> copyWithZone:]: >>> selector not recognized [self = 0x158c2400] >>> /Users/eloy/Documents/DEVELOPMENT/RubyCocoa/Nzb/hellanzb/build/ >>> Release/HellaNZB.app/Contents/Resources/rb_main.rb:22:in >>> `NSApplicationMain': NSInvalidArgumentException - *** -[Download >>> copyWithZone:]: selector not recognized [self = 0x158c2400] >>> (OSX::OCException) >>> from /Users/eloy/Documents/DEVELOPMENT/RubyCocoa/Nzb/hellanzb/ >>> build/ >>> Release/HellaNZB.app/Contents/Resources/rb_main.rb:22 >>> >>> As you can see the class of the object that it's being called on is >>> Download which is a NSObject subclass. >>> >>> Otherwise I will create a small app and see if I can replicate the >>> problem. >>> >>> Ciao, >>> Eloy >>> >>> On 8/4/07, Laurent Sansonetti <lsa...@ap...> wrote: >>>> copyWithZone: is part of the NSCopying protocol, which NSObject >>>> doesn't implement but NSCell does. >>>> >>>> http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSCopying_Protocol/Reference/Reference.html >>>> >>>> Laurent >>>> >>>> On Aug 4, 2007, at 6:05 PM, Eloy Duran wrote: >>>> >>>>> Hey Lrz, >>>>> >>>>> That would have been very nice! :) >>>>> However unfortunately NSObject doesn't implement copyWithZone... >>>>> >>>>>>> foo = OSX::NSObject.alloc.init >>>>> => #<OSX::NSObject:0x2e00e class='NSObject' id=0x159ac60> >>>>>>> foo.objc_methods.grep(/zone/i) >>>>> => ["zone"] >>>>> >>>>> Eloy >>>>> >>>>> On 8/4/07, Laurent Sansonetti <lsa...@ap...> wrote: >>>>>> Try: >>>>>> >>>>>> def copyWithZone(zone) >>>>>> copy = super_copyWithZone(zone) >>>>>> # set your attributes to copy >>>>>> # ex: >>>>>> # copy.title = self.title >>>>>> return copy >>>>>> end >>>>>> >>>>>> Laurent >>>>>> >>>>>> On Aug 4, 2007, at 5:53 PM, Eloy Duran wrote: >>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> I'm trying to write my own custom NSCell for a tableview. >>>>>>> However, the table view tries to call #copyWithZone on my >>>>>>> objects, >>>>>>> which are subclasses of NSObject. So I was trying to create a >>>>>>> working >>>>>>> #copyWithZone, but no matter what I do it always crashes >>>>>>> immediately. >>>>>>> For instance I have the following, but it doesn't even write to >>>>>>> the >>>>>>> console: >>>>>>> >>>>>>> def copyWithZone(zone) >>>>>>> puts 'COPY!' >>>>>>> copy = Download.allocWithZone(zone).init >>>>>>> self.instance_variables.each do |iv| >>>>>>> copy.instance_variable_set iv, self.instance_variable_get(iv) >>>>>>> end >>>>>>> return copy >>>>>>> end >>>>>>> >>>>>>> Backtrace: >>>>>>> >>>>>>> #0 0x90a594c0 in objc_msgSend () >>>>>>> #1 0xbfffc21c in ?? () >>>>>>> #2 0x0002b850 in ocid_to_rbobj () >>>>>>> #3 0x0002df10 in ocdata_to_rbobj () >>>>>>> #4 0x0003051a in ovmix_register_ruby_method () >>>>>>> #5 0x00031a98 in rbobj_call_ruby () >>>>>>> #6 0x00031075 in ovmix_register_ruby_method () >>>>>>> #7 0x0002f8b9 in init_ovmix () >>>>>>> #8 0x927fa468 in -[NSObject(NSForwardInvocation) forward::] () >>>>>>> #9 0x90a5ccc1 in _objc_msgForward () >>>>>>> #10 0x932aed02 in -[NSCell _setContents:] () >>>>>>> #11 0x932aec95 in -[NSCell setObjectValue:] () >>>>>>> #12 0x9353abaa in -[_NSPlaceholderTextFieldPlugin >>>>>>> showValue:inObject:] () >>>>>>> #13 0x93511593 in -[NSValueBinder showValue:inObject:] () >>>>>>> #14 0x93510938 in -[NSValueBinder >>>>>>> _adjustObject:mode:observedController:observedKeyPath:context:editableState:adjustState >>>>>>> :] >>>>>>> () >>>>>>> #15 0x9353a287 in -[NSValueBinder >>>>>>> updateTableColumnDataCell:forDisplayAtIndex:] () >>>>>>> #16 0x9353a9ef in -[NSTextValueBinder >>>>>>> updateTableColumnDataCell:forDisplayAtIndex:] () >>>>>>> #17 0x9353a1d6 in -[_NSBindingAdaptor >>>>>>> tableColumn:willDisplayCell:row:] () >>>>>>> #18 0x93402a9d in -[NSTableView >>>>>>> _sendDelegateWillDisplayCell:forColumn:row:] () >>>>>>> #19 0x933ea065 in -[NSTableView >>>>>>> _drawContentsAtRow:column:clipRect:] >>>>>>> () >>>>>>> #20 0x933e902b in -[NSTableView drawRow:clipRect:] () >>>>>>> #21 0x933e67ce in -[NSTableView drawRowIndexes:clipRect:] () >>>>>>> #22 0x933e56a4 in -[NSTableView drawRect:] () >>>>>>> #23 0x933113b1 in -[NSView _drawRect:clip:] () >>>>>>> #24 0x9331040b in -[NSView >>>>>>> _recursiveDisplayAllDirtyWithLockFocus:visRect:] () >>>>>>> #25 0x9330f473 in -[NSView >>>>>>> _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView >>>>>>> :] >>>>>>> () >>>>>>> #26 0x93310041 in -[NSView >>>>>>> _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView >>>>>>> :] >>>>>>> () >>>>>>> #27 0x93310041 in -[NSView >>>>>>> _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView >>>>>>> :] >>>>>>> () >>>>>>> #28 0x93310041 in -[NSView >>>>>>> _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView >>>>>>> :] >>>>>>> () >>>>>>> #29 0x93310041 in -[NSView >>>>>>> _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView >>>>>>> :] >>>>>>> () >>>>>>> #30 0x9330eb78 in -[NSThemeFrame >>>>>>> _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView >>>>>>> :] >>>>>>> () >>>>>>> #31 0x9330e362 in -[NSView >>>>>>> _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView >>>>>>> :] >>>>>>> () >>>>>>> #32 0x9330dc8e in -[NSView displayIfNeeded] () >>>>>>> #33 0x9330da32 in -[NSWindow displayIfNeeded] () >>>>>>> #34 0x9335dd6c in _handleWindowNeedsDisplay () >>>>>>> #35 0x9082dd6e in __CFRunLoopDoObservers () >>>>>>> #36 0x9082ce10 in CFRunLoopRunSpecific () >>>>>>> #37 0x9082cace in CFRunLoopRunInMode () >>>>>>> #38 0x92dec8d8 in RunCurrentEventLoopInMode () >>>>>>> #39 0x92debfe2 in ReceiveNextEventCommon () >>>>>>> #40 0x92debe39 in BlockUntilNextEventMatchingListInMode () >>>>>>> #41 0x93292465 in _DPSNextEvent () >>>>>>> #42 0x93292056 in -[NSApplication >>>>>>> nextEventMatchingMask:untilDate:inMode:dequeue:] () >>>>>>> #43 0x9328bddb in -[NSApplication run] () >>>>>>> #44 0x9327fd2f in NSApplicationMain () >>>>>>> #45 0x0003fc0d in ffi_call_SYSV () >>>>>>> #46 0x0003fbae in ffi_call () >>>>>>> #47 0x0003cfa0 in rb_ffi_dispatch () >>>>>>> #48 0x00035ca0 in find_bs_boxed_by_encoding () >>>>>>> #49 0x00221e09 in call_cfunc () >>>>>>> #50 0x002214f2 in rb_call0 () >>>>>>> #51 0x00222489 in rb_call () >>>>>>> #52 0x0021c34a in rb_eval () >>>>>>> #53 0x00217d9c in eval_node () >>>>>>> #54 0x00218369 in ruby_exec_internal () >>>>>>> #55 0x002183b3 in ruby_exec () >>>>>>> #56 0x002183dd in ruby_run () >>>>>>> #57 0x00033474 in RBApplicationMain () >>>>>>> #58 0x00002886 in main () >>>>>>> >>>>>>> So does somebody know of a good way of implementing this with >>>>>>> RubyCocoa? >>>>>>> >>>>>>> Cheers, >>>>>>> Eloy >>>>>>> >>>>>>> PS: I'm on svn rev 1983 >>>>>>> >>>>>>> ------------------------------------------------------------------------- >>>>>>> This SF.net email is sponsored by: Splunk Inc. >>>>>>> Still grepping through log files to find problems? Stop. >>>>>>> Now Search log events and configuration files using AJAX and a >>>>>>> browser. >>>>>>> Download your FREE copy of Splunk now >> http://get.splunk.com/ >>>>>>> _______________________________________________ >>>>>>> Rubycocoa-talk mailing list >>>>>>> Rub...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >>>>>> >>>>>> >>>>>> ------------------------------------------------------------------------- >>>>>> This SF.net email is sponsored by: Splunk Inc. >>>>>> Still grepping through log files to find problems? Stop. >>>>>> Now Search log events and configuration files using AJAX and a >>>>>> browser. >>>>>> Download your FREE copy of Splunk now >> http://get.splunk.com/ >>>>>> _______________________________________________ >>>>>> Rubycocoa-talk mailing list >>>>>> Rub...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >>>>>> >>>>> >>>>> ------------------------------------------------------------------------- >>>>> This SF.net email is sponsored by: Splunk Inc. >>>>> Still grepping through log files to find problems? Stop. >>>>> Now Search log events and configuration files using AJAX and a >>>>> browser. >>>>> Download your FREE copy of Splunk now >> http://get.splunk.com/ >>>>> _______________________________________________ >>>>> Rubycocoa-talk mailing list >>>>> Rub...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >>>> >>>> >>>> ------------------------------------------------------------------------- >>>> This SF.net email is sponsored by: Splunk Inc. >>>> Still grepping through log files to find problems? Stop. >>>> Now Search log events and configuration files using AJAX and a >>>> browser. >>>> Download your FREE copy of Splunk now >> http://get.splunk.com/ >>>> _______________________________________________ >>>> Rubycocoa-talk mailing list >>>> Rub...@li... >>>> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >>>> >>> >>> ------------------------------------------------------------------------- >>> This SF.net email is sponsored by: Splunk Inc. >>> Still grepping through log files to find problems? Stop. >>> Now Search log events and configuration files using AJAX and a >>> browser. >>> Download your FREE copy of Splunk now >> http://get.splunk.com/ >>> _______________________________________________ >>> Rubycocoa-talk mailing list >>> Rub...@li... >>> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Splunk Inc. >> Still grepping through log files to find problems? Stop. >> Now Search log events and configuration files using AJAX and a >> browser. >> Download your FREE copy of Splunk now >> http://get.splunk.com/ >> _______________________________________________ >> Rubycocoa-talk mailing list >> Rub...@li... >> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >> > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a > browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk |