You can think of it as a table of contents for the compiler.

Essentially, the table of contents that would have entries that represent each 
chapter in a book would be your forward declaration where the table of contents 
is the list of methods that are coming up in the .m file.

This allows the compiler to know the method names that it should expect to 
encounter before it start chewing on compiling code.  For example, if the 
compiler is compiling a method and that method has a call to another method 
(within the same class) that is defined after the method the compiler's working 
on.   

The compiler doesn't know it should be expecting this method name, it doesn't 
have any info from you that tells it that the method is a legit method in the 
first place, so it goes "um, you're telling me to make instructions for a call 
this thing and you haven't told me that it even exists in your class, thanks 
buddy."  And then it fails because you didn't tell it that.

It's like a street sign that says "bump ahead" so you can prepare for the bump, 
but for compilers.

Cool?



On Mar 22, 2013, at 4:16 AM, Diederik Meijer | Ten Horses wrote:

>> The forward declaration is used to tell the compiler: "The word MyClass 
>> represents a class. I don't give you the implementation yet, but it 
>> represents a class, and the implementation will be provided later".
> 
> …and this allows you to create a property for an instance of that class in 
> the .h that has the @class forward declaration. This way, you don't need to 
> put #import class.h in there. You will need to include that last line in the 
> .m in order for the property to work. So, in essence, you are putting your 
> #import statement in the implementation and use the @class in the interface 
> in order to reference its iVars in the .h
> 
> This is all done for performance reasons
> 
> 
> 
> 
> 
> 
> Op Mar 21, 2013, om 10:20 PM heeft Jean Suisse <jean.li...@gmail.com> het 
> volgende geschreven:
> 
>> A few minutes search gave me this. While I haven't taken a deep look to 
>> these resources, they do look good.
>> 
>> - What's a forward declaration ? (several languages including Obj-C)
>> http://en.wikipedia.org/wiki/Forward_declaration
>> 
>> - When to use a forward declaration (C++):
>> http://stackoverflow.com/questions/553682/when-to-use-forward-declaration
>> 
>> - Objective C Programming Tutorial | Using @class And #import Directives
>> http://www.youtube.com/watch?v=0b9Qok2uHhU
>> 
>> @class allows you to declare a class.
>> Example: @class MyClass;
>> 
>> The forward declaration is used to tell the compiler: "The word MyClass 
>> represents a class. I don't give you the implementation yet, but it 
>> represents a class, and the implementation will be provided later".
>> 
>> Jean
>> 
>> On 21 mars 2013, at 21:43, H Miersch <hmier...@me.com> wrote:
>> 
>>> hi.
>>> 
>>> what exactly does @class do?
>>> 
>>> and what does "forward declaration" mean?
>>> _______________________________________________
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>> 
>>> 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:
>>> https://lists.apple.com/mailman/options/cocoa-dev/jean.lists%40gmail.com
>>> 
>>> This email sent to jean.li...@gmail.com
>> 
>> _______________________________________________
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> https://lists.apple.com/mailman/options/cocoa-dev/diederik%40tenhorses.com
>> 
>> This email sent to diede...@tenhorses.com
>> 
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to