문제

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.

도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top