Dynamically subclassing an observed object

2010-10-13 Thread Dave DeLong
Hi everyone, I maintain some code that does dynamic subclassing to override an object's -dealloc method to do some extra cleanup prior to deallocation. (And for the curious, this cleanup is not necessary when using Garbage Collection) However, I observed a problem this morning, and that's

Re: Dynamically subclassing an observed object

2010-10-13 Thread Kyle Sluder
On Wed, Oct 13, 2010 at 12:44 PM, Dave DeLong davedel...@me.com wrote: What's involved with safely subclassing an object that's already been dynamically subclassed with KVO? You can't. See the comments here:

Re: Dynamically subclassing an observed object

2010-10-13 Thread Ken Thomases
On Oct 13, 2010, at 2:44 PM, Dave DeLong wrote: I maintain some code that does dynamic subclassing to override an object's -dealloc method to do some extra cleanup prior to deallocation. (And for the curious, this cleanup is not necessary when using Garbage Collection) As mentioned, it's

Re: Dynamically subclassing an observed object

2010-10-13 Thread Dave DeLong
Good questions. I know that this swizzling will only be happening on NSViews (since that's what my code operates on). As I mentioned in the original email, my current implementation exchanges -dealloc with a new one, which then invokes the original dealloc method. This appears to work well,

Re: Dynamically subclassing an observed object

2010-10-13 Thread Kyle Sluder
On Wed, Oct 13, 2010 at 2:02 PM, Dave DeLong davedel...@me.com wrote: As for the rationale behind why I need to do this, I'll just refer to my blog post on the matter:   http://davedelong.com/blog/2010/10/07/fun-objective-c-dynamic-subclassing Funny enough, it sounds like the blog post I

Re: Dynamically subclassing an observed object

2010-10-13 Thread Dave DeLong
Yeah, thanks for this. I've been over Mike's code, and he gets around this issue by using class_setSuperclass(), which the documentation says should not be used. How would using a CFDictionary with custom callbacks make things any better? In order to find things in the dictionary, things are

Re: Dynamically subclassing an observed object

2010-10-13 Thread Dave DeLong
Ah, I think I see what you're saying. I could create a custom CFDictionaryHashCallBack to simply return the pointer value or something, thereby skirting the -hash problem. Intriguing. I'll play with this and report back. The thing I have against this approach is that it potentially allows