13

I am receiving the warning Incompatible pointer types sending 'Class' to parameter of type 'id' in the line "delegate:self" below:

    + (SHKActionSheet *)actionSheetForType:(SHKShareType)type
{
    SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"Share")
                                                      delegate:self
                                             cancelButtonTitle:nil
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:nil];
    as.item = [[[SHKItem alloc] init] autorelease];
    as.item.shareType = type;

This warning is in ShareKit, if anyone knows how to fix it, please let me know!

geon
  • 8,128
  • 3
  • 34
  • 41
SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191

3 Answers3

21

You are trying to pass self parameter in a static method. It is not right as there is no particular instance of this object in static methods. Make it either non static method or pass some instance of this class as delegate.

Nikita Leonov
  • 5,684
  • 31
  • 37
  • 1
    How would I pass an instance of the class as delegate? Do you have ShareKit, did you fix this warning? – SimplyKiwi Aug 09 '11 at 02:36
  • You see you has a + near your method. This mean that it is static method and can be called without specifying particular instance of the class but just calling directly method of your class in a form [MyClass method]; Is it answers your question? – Nikita Leonov Aug 09 '11 at 02:40
  • It needs to be a + method though, otherwise it will break the feature – SimplyKiwi Aug 09 '11 at 02:41
  • In this case you need to initialize an instance of a class in a way [[MyClass] alloc] initSomething]; retain it, store it in a static variable to avoid unexpected dealloc and pass as delegate. At the same time you will need to care of proper releasing of this instance when time will come. – Nikita Leonov Aug 09 '11 at 02:44
9

When working with a static Class, you can manually get ride of the warning:

delegate:(id<UIActionSheetDelegate>)self
Cœur
  • 37,241
  • 25
  • 195
  • 267
3

Try using nil instead of self (xcode 4.2 iOS 5).

Sonny Parlin
  • 931
  • 2
  • 13
  • 28