Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find protocol declaration for 'MyObjectViewDelegate' when it is CLEARLY there ?1

I have a class like this..

#import "MyObjectAddView.h"
#import "MyAppDelegate.h"

#define myAppDelegate (MyAppDelegate *) [[UIApplication sharedApplication] delegate]

@class MyObjectAddView;

@interface AccountViewController : UIViewController <UIScrollViewDelegate, MyObjectAddViewDelegate, UIImagePickerControllerDelegate> {

    MyObjectAddView *myAddView;
    .....
}

@property (nonatomic, retain) IBOutlet MyObjectAddView *myAddView;

- (id) initWithSettings:(SettingsObject *)settings;

@end

WHY is it suddenly telling me that it Cannot find protocol declaration for 'MyObjectAddViewDelegate' when I'm clearly importing and including the @class for where the protocol is defined? Here how MyObjectAddView setup:

#import <UIKit/UIKit.h>
#import "MyAppDelegate.h"

#define myAppDelegate (MyAppDelegate *) [[UIApplication sharedApplication] delegate]

@protocol MyObjectAddViewDelegate;

@interface MyObjectAddView : UIView <UITextFieldDelegate> {

@private
    id <MyObjectAddViewDelegate> delegate;
    ....    
@public
    .....
}

@property(nonatomic, assign) id <MyObjectAddViewDelegate> delegate;
.....

@end

@protocol MyObjectAddViewDelegate <NSObject>
// expense == nil on cancel
- (void)myObjectAddViewDidFinish:(MyObjectAddView *)addView;

@end

Everything seems perfectly setup and I don't see any circular imports ?! Any suggestions why it might not be seeing the protocol definition in MyObjectAddView?

Thanks.

like image 486
skålfyfan Avatar asked Mar 24 '11 20:03

skålfyfan


2 Answers

You do not need a forward reference to a class after you have imported the header for that class. Only time you do a forward reference is if you plan on including the header inside of the implementation file. Remove @class MyObjectAddView and if that fixes it let me know if not I may have another solution for you.

like image 77
Joe Avatar answered Oct 14 '22 06:10

Joe


Synthesizing the discussion: another solution is to check for cyclical imports between the delegate implementation and protocol declaration. This solved my issue.

like image 44
jturolla Avatar answered Oct 14 '22 06:10

jturolla