• 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 causing grief
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @class causing grief


  • Subject: Re: @class causing grief
  • From: Ron Fleckner <email@hidden>
  • Date: Tue, 18 Mar 2008 19:27:37 +1100


On 18/03/2008, at 6:32 PM, Scott Squires wrote:


I'm starting to go in circles at this point.
I know I've got a number of interconnecting files.
Since I was getting errors I replaced the #import as much as possible with @class defines


I'm still getting the following error:
error: syntax error before 'AT_NAME' token

This indicates @class myClass; in the following examples.
Most of these work fine but if I end up swapping #import instead then other areas break the compiler.


Any suggestions on areas to look at (missing @end or something else?)

Thanks.

example:

#import <stdStuff/stdStuff.h>
@class myClass;

@interface anotherClass : NSObject
{

	myClass *theMyClassObject;

}

@end

Hi Scott,

The @class MyClass; declaration is a forward declaration to tell the compiler that MyClass is, in fact, a valid type that you define elsewhere (ie, in it's .h and .m files). You only need to do it in a header file of another class which makes use of your MyClass as an instance variable.

The #import "MyClass.h" is a preprocessor macro which will, as it's name suggests, import the contents of that file into whatever file in which it appears.

So, make sure you only have @MyClass declarations in header files of classes in which you need a MyClass type instance variable, and then #import "MyClass.h" into that class's implementation (.m) file. You would do this for every class which requires an instance of MyClass in it. Do this and you should be sweet.

By the way, it's the convention to name classes with an initial capital. Otherwise they are easy to confuse with instance variables.

MyClass *myClassIvar = [[MyClass alloc] init];

HTH,

Ron
_______________________________________________

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 causing grief (From: Scott Squires <email@hidden>)

  • Prev by Date: CoreData code working on Tiger - not on Leopard
  • Next by Date: Re: @class causing grief
  • Previous by thread: @class causing grief
  • Next by thread: Re: @class causing grief
  • Index(es):
    • Date
    • Thread