开发者

Undeclared identifier __bridge on xcode

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 CFU开发者_Python百科UIDRef
return (__bridge NSString *) str;

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

Use of undeclared identifier '__bridge'

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

=== UPDATED ===

The full code:

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

The uuid is generated by:

uuid = CFUUIDCreate(NULL);


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

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜