Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve the "Expected a type" error in ios

Tags:

ios

Am new to development.I got an error regarding the "Expected a Type" error.In two classes of my application,i declared the method in one class and in another class i used that method with the help of @protocol method.How to resolve it.Two classes DayButton.h and DDCalenderView.h In DayButton.h, i declared as

 @protocol DayButtonDelegate <NSObject>
-(void)dayButtonPressed:(id)sender;
@end

And in DDCalenderView.h,i wrote as

@protocol DDCalenderViewDelegate<NSObject>
-(void)dayButtonPressed:(DayButton *)button;

Getting an exception near void method in DDCalenderView.h

like image 577
user1464243 Avatar asked Dec 27 '22 22:12

user1464243


2 Answers

SOLUTION: Move the import from the implementation to the header file. I think that there were some imports in the implementation file that were not in the header file.Make sure that you have the correct import. It’s one of those little bugs/mistakes that make you shake your head… at yourself.

like image 185
Ratnakar Avatar answered Jan 14 '23 14:01

Ratnakar


In DDCalenderView.h you should type @class DayButton; above @protocol DDCalenderViewDelegate<NSObject>. This will tell the compiler that DayButton is a class (that is declared somewhere else).

You can also add #import "DayButton.h" to the top of DDCalenderView.h.

like image 27
Jelle Avatar answered Jan 14 '23 14:01

Jelle