0

Possible Duplicate:
@class vs. #import

I am Really confused with this,Whats the difference between writing @classname & #import"classname.h" .When Do we go for @classname?

Community
  • 1
  • 1
Shantanu
  • 3,086
  • 3
  • 25
  • 32

5 Answers5

1

You can find a good answer here and in the Objective-C Programming Language documentation on ADC

Community
  • 1
  • 1
GreyHands
  • 1,734
  • 1
  • 18
  • 30
0

@classname is a forward declaration. Nothing gets imported, it just informes the compiler, that the class will exist on runtime.

#import will actually import the other class -> you can imagine it as a copy it into the file. so the imported classes will get compiled before the one, that it is written in.

calimarkus
  • 9,955
  • 2
  • 28
  • 48
0

@classname just tells the compiler that the class classname exists.

#import really imports the header file so that the compiler not only knows that it exists, but also how it looks. (like ivars, methods etc...)

calimarkus
  • 9,955
  • 2
  • 28
  • 48
Christian Schnorr
  • 10,768
  • 8
  • 48
  • 83
0

The @classname just let's the compiler know that the class exists however you'll still need to import the corresponding .h. You can use the @classname in the .h and then import the class in the .m and this will allow you to avoid circular references. You can read more about it here Apple Docs

ScottPetit
  • 814
  • 5
  • 6
0

@className directive is introduced to overcome cyclic reference of classes, it is also known as Forward Declaration

@class will just inform the compiler that there is a class named "@className yourClass" no need to worry about that class and in runtime it just refer that class and executes.

#import "className" will keep a copy of that particular class.

Joe
  • 56,979
  • 9
  • 128
  • 135
taus-iDeveloper
  • 681
  • 2
  • 8
  • 22