开发者

Compiler warning when passing NSError ** as a method parameter

I've been scratching my head about this for the last 4 hours, trying out all kinds of little experiments, but I can't seem to figure out what's going wrong. Could this be a compiler bug?

Test.m:

- (id)initWithContentsOfURL:(NSURL *)aURL error:(NSError **)error
{
    if (!(self = [super init])) {
        return nil;
    }
    return self;
}

main.m:

NSError *error;

Test *t = [[Test alloc] initWithContentsOfURL:[NSURL fileURLWithPath:@"/"] error:&error];

Here's the compiler warning (from main.m):

warning: incompatible Objective-C types 'struct NSError **', expected 'struct NSDictionary **' when passing argument 2 of 'initWithContentsOfURL:error:' from distinct Obj开发者_JAVA技巧ective-C type

I'm using the latest versions of Xcode and Snow Leopard.


I suspect that it's picking up a different instance of the selector, initWithContentsOfURL:error: - perhaps the one in NSAppleScript. Remember that [NSObject alloc] returns an id.

Does your code work as expected at runtime?

Try casting the return of [Test alloc] to Test*.

i.e.


Test *t = [(Test*)[Test alloc] initWithContentsOfURL:[NSURL fileURLWithPath:@"/"] error:&error];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜