• 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
Re: Changing classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing classes


  • Subject: Re: Changing classes
  • From: Keary Suska <email@hidden>
  • Date: Thu, 30 Sep 2010 13:40:17 -0600

On Sep 30, 2010, at 1:28 PM, Remco Poelstra wrote:

> Hi,
>
> I've a class that represents a general piece of hardware. Subclasses of that class represent more specific versions of that hardware. When I scan the network for hardware, I first only know some basic properties of the hardware and only after some more queries I'll know all details. I thought it would be a good thing to instantiate from the base class when I detect the hardware and then change the class to a more specific class as I find out more about the hardware.
> But how do I change a class? I know about the ISA pointer, but changing it doesn't allocate any additional variables.
> What would be a nice solution to this problem?

Why not just allocate a new object to replace the existing one? E.g.:

id hardware = [[HardWare alloc] init];
[someDictionary setObject:hardware forKey:@"newHardware"];
[hardware release];	// owned only by dict
...
// now you know the specific hw properties
USBHardware *usbHardWare = [[USBHardware alloc] init];
[someDictionary setObject: usbHardWare forKey:@"newHardware"];
[usbHardWare release];

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Changing classes (From: Remco Poelstra <email@hidden>)

  • Prev by Date: Re: Changing classes
  • Next by Date: Re: Changing classes
  • Previous by thread: Re: Changing classes
  • Next by thread: Re: Changing classes
  • Index(es):
    • Date
    • Thread