Reputation: 14509
Say, I want to call a UIActionSheet from a helper class method. I want the helper class (not the object) to be the delegate of this actionsheet. So I'm passing self to the delegate.
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"MyTitle"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:@"Delete"
otherButtonTitles:nil];
My helper class implements the delegate methods as class methods and everything works fine. But, I get a warning from the compiler that says, Incompatible pointer, sending Class when id is expected. I also tried [self class] and getting the same warning.
How can I avoid this warning?
Upvotes: 4
Views: 3145
Reputation: 1
I solve it by adding < UIActionSheetDelegate > at the class .h file interface declaration
Upvotes: 0
Reputation:
You won't quite the warning until you pass an object pointer to the method. It expects an id
, where you give Class
which is a typedef struct objc_class *Class;
.
Upvotes: 0
Reputation: 39935
You can get rid of the warning by casting self to type id.
[[UIActionSheet alloc] initWithTitle:@"MyTitle"
delegate:(id<UIActionSheetDelegate>)self
cancelButtonTitle:nil
destructiveButtonTitle:@"Delete"
otherButtonTitles:nil];
This will tell the compiler to treat the value as an id
which conforms to the UIActionSheetDelegate protocol.
Upvotes: 7