Is there a way to suppress a compile error?
I cannot use protocols in this case because the class I am trying to use is in an external library. I have no control over the code
if (myClass && [[myClass class] respondsToSelector:@selector(getSomething)])
{
// Compile error on the line below
MyResult *result = [myClass getSomething];
// Also tried
MyResult *result = [(id)myClass getSomething];
}
EDIT:
Error: No known class method for selector
When you use a method on an untyped Objective-C object, the compiler tries to guess which method you’re trying to call based on its selector, because it needs to generate different code depending on the return value. The way code is generated is also different depending on if you use ARC or not, and the compiler needs change accordingly.
Without ARC, the compiler will assume the return type is
idfor any selector it doesn’t know of, and will generate a warning. With ARC, it becomes a hard error because the compiler doesn’t want to take a chance at memory management.That’s why you at least need to tell the compiler about one existing declaration of the method.