Xcode上未声明的标识符__bridge [英] Undeclared identifier __bridge on xcode

查看:157
本文介绍了Xcode上未声明的标识符__bridge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将CFUUIDRef转换为NSString *.

I am trying to convert a CFUUIDRef to a NSString *.

之前,我使用以下代码,并且工作正常.

Before, I used the following code, and worked fine.

CFStringRef str = CFUUIDCreateString(NULL, _uuid); # _uuid is of type CFUUIDRef
return (__bridge NSString *) str;

但是,在最近更新了Xcode(或其他我没有注意到的东西)之后,上面的代码给了我错误:

However, after a recent update on Xcode (or other thing that I didn't notice?), the above code gives me the error:

使用未声明的标识符'__bridge'

那么我做错了什么吗?我该怎么解决?

So have I did something wrong? How could I solve it?

===更新===

完整代码:

+ (NSString *)uuidToString:(CFUUIDRef)_uuid {
  CFStringRef str = CFUUIDCreateString(NULL, _uuid); # _uuid is of type CFUUIDRef
  return (__bridge NSString *) str;
}

uuid由以下方式生成:

The uuid is generated by:

uuid = CFUUIDCreate(NULL);

推荐答案

__bridge仅在启用ARC(自动引用计数)的情况下定义.它用于将对象移入和移出ARC控制". ()

__bridge is only defined with ARC (Automatic Reference Counting) enabled. It is used to "transfer objects in and out of ARC control". (Source)

要打开ARC,请转到您的构建设置,然后将Objective-C Automatic Reference Counting设置为Yes.

To turn on ARC, go to your build settings and set Objective-C Automatic Reference Counting to Yes.

或者,如果您不想使用ARC,只需删除__bridge,它就可以正常工作.

Or, if you do not want to use ARC, simply remove __bridge and it should work fine.

这篇关于Xcode上未声明的标识符__bridge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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