I have an init method that takes an (id) argument:
-(id) initWithObject:(id) obj;
I'm trying to call it like this:
[[MyClass alloc] initWithObject:self];
But XCode is complaining about the argument being a "distinct Objective-C type" (which usually indicates a type mismatch or level of indirection error).
If I explicitly cast self to (id) the warning goes away. In either case the code runs as expected. Interestingly, on the next line I'm passing self to another method that also takes an id, and that works fine.
I'm wondering if I'm missing something subtle - or is it a peculiarity of the compiler?
I'm not entirely comfortable just casting it until I'm sure of the reasons why it's necessary.
[Edit]
I've been asked to supply more code. Not sure there's much else that's relevant. Here's my actual code that makes the call. Note that it is, itself, within an init method. It's the call to initWithSource
that's giving the warning:
-(id) initWithFrame:(CGRect) frame
{
self = [super initWithFrame: frame];
if( self )
{
delegate = nil;
touchDelegate = [[TBCTouchDelegate alloc] initWithSource:self];
[touchDelegate.viewWasTappedEvent addTarget: self action:@selector(viewWasTapped:)];
}
return self;
}
And here's the init method being called:
-(id) initWithSource:(id) sourceObject
{
self = [super init];
if (self != nil)
{
// Uninteresting initialisation snipped
}
return self;
}