Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No method found compiler warning

I create a class from a string, check it is valid and then check if it responds to a particular method. If it does then I call the method. It all works fine, except I get an annoying compiler warning: "warning: no '-setCurrentID:' method found". Am I doing something wrong here? Is there anyway to tell the compiler all is ok and stop it reporting a warning?

The here is the code:

// Create an instance of the class
id viewController = [[NSClassFromString(class) alloc] init];

// Check the class supports the methods to set the row and section
if ([viewController respondsToSelector:@selector(setCurrentID:)]) 
    {
        [viewController setCurrentID:itemID];
    }   

// Push the view controller onto the tab bar stack      
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];

Cheers

Dave

like image 410
Magic Bullet Dave Avatar asked Apr 14 '26 13:04

Magic Bullet Dave


1 Answers

Either import the header which declares the method or just use an informal protocol in your implementation to declare it. The compiler has to know the signature of the method.

@interface NSObject (MyInformalProtocol)

- (void)setCurrentID:(int)id;

@end
like image 64
Nikolai Ruhe Avatar answered Apr 16 '26 03:04

Nikolai Ruhe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!