• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
isa swizzling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

isa swizzling


  • Subject: isa swizzling
  • From: Hamish Allan <email@hidden>
  • Date: Fri, 1 Apr 2005 18:33:47 +0100


On Apr 1, 2005, at 3:31, Hamish Allan wrote:

So my next question is, can I get away with updating the class pointers of these existing objects from %WebBookmarkProxy to WebBookmarkProxy, and if so, how do I go about doing it?

To address my own question, I seem to have gotten away with the following:


...
NSString *className = [[existingObject class] description];
if ([className hasPrefix:@"%"])
{
Class posingClass = NSClassFromString([className substringFromIndex:1]);
if (posingClass)
[existingObject becomeClass:posingClass];
}
...
@implementation NSObject (IsaSwizzler)
- (void)becomeClass:(Class)newClass
{
self->isa = newClass;
}
@end
...


Now, I suspect that this is quite dangerous in certain circumstances, but I'm planning only to use it to find out how certain classes work whose instances are all created before the InputManager +loads. When I've done my research I'll leave the existing objects well alone! I just thought I would post this here in case somebody else tries to do the same in future: if I find any gotchas I'll post them in this thread.

Best wishes,
Hamish

_______________________________________________
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


  • Prev by Date: Re: More Newbie Trouble with Basic Bindings
  • Next by Date: Scaling Fonts;
  • Previous by thread: Re: NSCopying is manual labor
  • Next by thread: Scaling Fonts;
  • Index(es):
    • Date
    • Thread