views:

76

answers:

2
@protocol MyViewDelegate <NSObject>
- (void) didFinishProcessing:(MyView*)myView; //compiler stops here with error
@end

@interface MyView : MySuperclass {

id<MyViewDelegate> _delegate;       
}

@property (nonatomic, retain) id<MyViewDelegate> delegate;

@end

When I try to compile I get " expected ')' before MyView ". Where is the error?

+5  A: 

Before @protocol add the line @class MyView. At that point the compiler doesn't yet know about your MyView class.

Johan Kool
great, now I have another question for you. What is the difference between #import "MyView.h" and @class MyView;? I thought there is no difference but obviously there is because if I just import the class it doesn't work so I needed the line of code you provided.
Horatiu Paraschiv
Matt S
Horatiu, @class just tells the compiler not to pay attention on any error connected to this class. #import imports the contents of the file if they weren't imported yet. In your case you are already in that file - I believe that `#import "MyView.h"` inside "MyView.h" will do nothing...
Michael Kessler
Great, thanks for your explanation.
Horatiu Paraschiv
+3  A: 

MyView is not recognized by the compiler, which is why it expected a close paren before it. This is because the class is defined below the MyViewDelegate protocol, so the compiler has not yet seen it. Add

@class MyView;

above the protocol declaration to fix it.

bobDevil