Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 CFUUIDRef
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);
like image 883
PeterWong Avatar asked Aug 15 '11 09:08

PeterWong


1 Answers

__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.

like image 192
Pontus Granström Avatar answered Sep 29 '22 18:09

Pontus Granström