self.delegate respondsToSelector: ... does not compile
-respondsToSelector:
is a method on NSObject. Either assume that your id
delegate is in fact an NSObject, and cast it:
[(NSObject*)self.delegate respondsToSelector:@selector(myClass:willDoSomething:)]
Or, better, make your delegate explicitly an NSObject:
@property (nonatomic, weak) NSObject<MyClassDelegate>* delegate;
Or make the protocol be a sub-protocol of NSObject:
@protocol MyClassDelegate <NSObject>
Basically you are saying that your delegate is constrained only by your <MyClassDelegate>
protocol so the compiler assumes that those are the only methods available. What you need to do is have the protocol extend <NSObject>
like so:
@Protocol MyClassDelegate <NSObject>- (void)myClass:(MyClass *)sender willDoSomething:(BOOL)animated;@end
That way the compiler knows that any object which conforms to your protocol also conforms to the <NSObject>
protocol which defines respondsToSelector:
.