Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - import vs forward declaration regarding setAlpha

I'm trying to do some animations on an object that I have setup via IB. I'm adding a forward declaration to my .h like so:

@class MySpecialClass;

and then setup a property like so:

@property (nonatomic, retain) IBOutlet MySpecialClass *specialClass;

I want to be able to hide the specialClass using setAlpha, but I get the following error from xcode when trying to compile.

Receiver type 'MySpecialClass' for instance message is a forward declaration.

Do I need to import my class instead of a forward declaration? I'd like to not have to import anything unnecessary if I don't have to.

like image 668
Romes Avatar asked May 07 '12 18:05

Romes


2 Answers

Forward declaration just tells the compiler, "Hey, I know I'm declaring stuff that you don't recognize, but when I say @MyClass, I promise that I will #import it in the implementation".

You use forward declaration to prevent stuff like circular includes (MyClass imports YourClass which imports MyClass which...), but the 'promise' you make with your code, is that you'll #import it later

like image 149
JoeCortopassi Avatar answered Oct 30 '22 09:10

JoeCortopassi


You need to import it. Forward declaration is just to silence the compiler that this class exists, but it has no idea about its members, methods, properties, size...

like image 31
graver Avatar answered Oct 30 '22 09:10

graver