Reputation: 9076
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
Upvotes: 3
Views: 2252
Reputation: 81848
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
Upvotes: 7