Having just spent ages debugging this, I'm keen to understand what exactly is going on!
In a very contrived example, let's say we have two objects, Object1 has this method:
- (void) testMethod:(NSString *)testString
Object 2 has this method:
- (void) testMethod:(NSArray *)testArray
Then, back in Object1, there's the following code in a method:
NSArray *myArray = [[NSArray alloc] init];
[[[Object2 alloc] init] testMethod:myArray];
When I compile, Xcode gives a warning:
Incompatible pointer types sending 'NSArray *' to parameter of type 'NSString *'
I believe I'm right in saying the warning occurs because I never actually specify the type of Object2. Explicitly casting the object to Object2 fixes it, but my questions are thus:
- When calling testMethod on Object2, why is it using the method from Object1, when the objects are nothing to do with each other?
- Why does the warning vanish if I move
#import "Object2.h"
into Object1.h instead of Object1.m?
Thank you!