I have a class, let’s call it ABC, with an NSArray *objects property, and the objects in the NSArray can be one of two different classes, X and Y. Both X and Y have a path property, but the compiler doesn’t know this.
Therefore, even though ABC will always find the path property on my array objects, I get compiler warnings on my code — “No ‘path’ method found”. App runs fine but I’m getting annoyed by the warnings. How can I fix my code (with protocols?) so that the compiler stops complaining?
Thank you!
You need to import some header that declares a
pathmethod. When it’s compiling your code, the compiler looks at the list of methods this file knows about and it sees that there is nopathmethod. You just need to tell it that the method exists and its signature is whatever and the compiler will be satisfied. No protocol is necessary.