Swapping isa's (was Re: Hex Edit controls (resknife))
Swapping isa's (was Re: Hex Edit controls (resknife))
- Subject: Swapping isa's (was Re: Hex Edit controls (resknife))
- From: glenn andreas <email@hidden>
- Date: Tue, 30 Nov 2004 13:36:38 -0600
On Nov 30, 2004, at 12:48 PM, John Stiles wrote:
On Nov 30, 2004, at 10:46 AM, Andrew Farmer wrote:
On 29 Nov 2004, at 19:19, Jeff Laing wrote:
I have to say, I'm not sure that the following is legal.
@implementation NSTextView (HexTextView)
- (void)swapForHexTextView
{
isa = [HexTextView class];
}
@end
Is 'isa' really writeable? Is this not going to crash and burn???
Believe it or not, it is.
Of course, "it's writable" is a separate statement from "it isn't
going to crash and burn." That one is really kind of up in the air
AFAIK :) I think you are probably open to memory leaks and all sorts
of other potential problems if you go this route.
Changing isa is usually only safe if the old class and the new class
have the same instance variable layout (such as having the new class be
a subclass of the old one without any new instance variables). In
general, though, you are better off adding the new class to IB and
setting it in your NIB to start with (and then you can have additional
ivars in your subclass).
However, combining isa-swapping with dynamic class creation (and
installing methods at runtime as well) allows for things like "per
instance methods" (you make a subclass for that instance only, add the
IMPs to it, and swap the isa).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden