• 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: id versus Class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: id versus Class


  • Subject: RE: id versus Class
  • From: "Mondragon, Ian" <email@hidden>
  • Date: Wed, 05 Mar 2003 15:03:44 -0600

yes and no :-)

you are correct about the id - it's a generic pointer to an instance whose
class is not known until runtime. but the Class is a pointer to a *class*
structure (not an instance of it) whose identity is not known until runtime
- think of it as an id for classes themselves, rather than instances:

Class unknownClass = Nil; // capital "N" for classes
id unknownInstance = nil; // lower-case "n" for instances

// act like you really want a new instance of a pre-existing object
called "someRandomObject"...
unknownClass = [someRandomObject class];
unknownInstance = [[unknownClass alloc] init];

// now do whatever you will...

- ian

> -----Original Message-----
> From: Britt Green [SMTP:email@hidden]
> Sent: Wednesday, March 05, 2003 2:43 PM
> To: email@hidden
> Subject: id versus Class
>
> > Message: 15
> > Date: Wed, 05 Mar 2003 13:08:57 -0600
> > From: "Mondragon, Ian" <email@hidden>
> > Subject: RE: Newbie coming to Cocoa from the world of C++
> > To: email@hidden, email@hidden
>
> <in deletia>
>
> > 4) an id is an un-typed pointer to an object instance (determined at
> > runtime). a Class is a pointer to a class data structure:
> >
> > id foo = [[AnyClass alloc] init];
> > id bar
> > Class baz = [AnotherClass class];
> >
> > bar = [[baz alloc] init];
>
> So id is used when the class may not be known, and Class is used when
> the object *is* known, correct?
>
> > hope that helps a bit...
>
> It does. Thank you, and to everyone else who wrote me, answering my
> questions.
>
> Best,
>
> Britt
>
> =====
> "The ocean, she is strange and wonderous, filled with animals that disturb
> even a Frenchman."
> Yahoo! Tax Center - forms, calculators, tips, more
> http://taxes.yahoo.com/
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: "Constant" strings are static or autoreleased?
  • Next by Date: Re: "Constant" strings are static or autoreleased?
  • Previous by thread: id versus Class
  • Next by thread: Re: Solutions for the shfiting sheet bug?
  • Index(es):
    • Date
    • Thread