Question

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 Objective-C type

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

Was it helpful?

Solution

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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top