• 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: @class create a new instance?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @class create a new instance?


  • Subject: Re: @class create a new instance?
  • From: Kyle Sluder <email@hidden>
  • Date: Mon, 25 Apr 2011 08:24:17 -0700

On Mon, Apr 25, 2011 at 8:02 AM, Rodrigo Zanatta Silva
<email@hidden> wrote:
> HI, someone said to me that *@class* directive create a new instance of the
> class automatic. I tried to find information about this, but didn't found.

They were wrong.

> For me, @class is only to solve cyclic includes. There are any side effect
> using it? The object variable is the same in this 2 example below, or there
> are some difference? The instance *instanceMyClass* will be the same of the
> class that send the pointer, right? And I will not lose any memory right?

You are correct. It's called a forward declaration, and is used to
resolve cyclic includes or reference class names in header files when
the actual definition isn't necessary.

Say you have MyClass.h:

// MyClass.h

@interface MyClass : NSObject {
  OtherClass *ivar;
}
- (OtherClass *)myIvar;
@end

The compiler doesn't actually need to know the definition of
OtherClass; it just needs to know that OtherClass refers to a class.
So instead of #import "OtherClass.h", you could use @class OtherClass
at the top of MyClass.h; this makes compiling MyClass.h much faster.

--Kyle Sluder
_______________________________________________

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: 
 >@class create a new instance? (From: Rodrigo Zanatta Silva <email@hidden>)

  • Prev by Date: Re: BSD TCP Programming on iPad
  • Next by Date: Re: BSD TCP Programming on iPad
  • Previous by thread: @class create a new instance?
  • Next by thread: Re: @class create a new instance?
  • Index(es):
    • Date
    • Thread