Tyilo
Tyilo

Reputation: 30102

Cast NSURL ** to CFURLRef *

How can I compile the following code using ARC?

int main() {

    NSURL *url = [NSURL new];
    NSURL * __strong *urlPointer = &url;
    CFURLRef *cfPointer = (__bridge CFURLRef *)urlPointer;
    geturl(cfPointer);
    NSLog(@"Got URL: %@", url);
    return 0;
}

I get the following error:

Incompatible types casting 'NSURL *__strong *' to 'CFURLRef *' (aka 'const struct __CFURL **') with a __bridge cast

I know that CFURLRef is already a pointer, so CFURLRef * is a pointer to a pointer, however the external function I'm using (geturl), is requiring a CFURLRef * as parameter. I have no control over the function, so I can't change that.

How can I cast the urlPointer to a CFURLRef * pointer?

Upvotes: 3

Views: 5052

Answers (1)

warrenm
warrenm

Reputation: 31782

Most of what you're doing is just convoluted pointer calisthenics. Why not just do this:

CFURLRef cfPointer = NULL;
geturl(&cfPointer);
NSURL *url = (__bridge NSURL *)cfPointer;
NSLog(@"Got URL: %@", url);

Upvotes: 10

Related Questions