将NSURL **转换为CFURLRef * [英] Cast NSURL ** to CFURLRef *

查看:451
本文介绍了将NSURL **转换为CFURLRef *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ARC编译以下代码?

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;
}

我收到以下错误:

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

我知道CFURLRef已经是一个指针,所以CFURLRef *是一个指针的指针,但是我正在使用的外部函数(geturl)需要一个CFURLRef *作为参数. 我无法控制该功能,因此无法更改.

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.

如何将urlPointer强制转换为CFURLRef *指针?

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

推荐答案

您正在做的大多数事情都是徒劳的指针健美操.为什么不这样做:

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);

这篇关于将NSURL **转换为CFURLRef *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆