I have a class with an delegate property. Anyone who wants to be a delegate must conform to a protocol. I defined everything like this:
#import <UIKit/UIKit.h>
@protocol TheDelegateProtocol;
@interface MyClass : UIView {
id<TheDelegateProtocol> theDelegate;
}
@property (nonatomic, assign) id<TheDelegateProtocol> theDelegate;
@end
@protocol TheDelegateProtocol<NSObject>
@required
- (void)fooBarWithFoo:(CGFloat)foo;
@end
Now the crazy thing is: I have another class that wants to be the delegate. So it conforms to that protocol, like this:
#import <Foundation/Foundation.h>
@class MyClass; // forward declaration. importet in implementation.
@protocol TheDelegateProtocol; // need forward declaration here, right?
@interface OtherClass : NSObject <TheDelegateProtocol> {
// ivars
}
@end
I can't get that to work. It says: "No definition of protocol 'TheDelegateProtocol' found". Well, that protocol is defined in MyClass, and I am importing MyClass in the implementation. Any idea what's wrong there?
Figured out something: In a method where I try to assign the protocol, it is telling me, that OtherClass does not conform to the protocol. But it does! That makes no sense. I also added the protocol method in the header....