我有一个带有(id)参数的init方法:
-(id) initWithObject:(id) obj;
Run Code Online (Sandbox Code Playgroud)
我试着像这样称呼它:
[[MyClass alloc] initWithObject:self];
Run Code Online (Sandbox Code Playgroud)
但是XCode抱怨该参数是一个"不同的Objective-C类型"(通常表示类型不匹配或间接错误的级别).
如果我明确地将自己转换为(id)警告就会消失.在任何一种情况下,代码都按预期运行.有趣的是,在下一行我将自己传递给另一个也带有id的方法,并且工作正常.
我想知道我是否遗漏了一些微妙的东西 - 或者它是编译器的特性?
直到我确定为什么必要的原因,我才完全放心.
[编辑]
我被要求提供更多代码.不确定还有其他相关的东西.这是我打电话的实际代码.请注意,它本身就是一个init方法.这是initWithSource给出警告的呼吁:
-(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;
}
Run Code Online (Sandbox Code Playgroud)
这是调用的init方法:
-(id) initWithSource:(id) sourceObject
{
self = [super init];
if (self != nil)
{
// Uninteresting initialisation snipped
}
return self;
}
Run Code Online (Sandbox Code Playgroud)