Should I use __bridge or __bridge_retained if I connect an auto-implemented object to Core Foundation?

The ARC migration tool has problems with this:

NSURL *fileURL = [NSURL fileURLWithPath:path]; AudioFileOpenURL((CFURLRef)fileURL, kAudioFileReadPermission, 0, &fileID); 

In particular, he is not sure whether he should use __bridge or __bridge_retained. And me too.

-fileURLWithPath returns an object with automatic implementation, and in this place I do not own the fileURL file. But at the same time, the object has a conservation rate of at least +1.

I would say that this should only be done with __bridge.

+7
source share
1 answer

You want to use regular __bridge just for this. You would use __bridge_retained only if you want to control the life cycle of a CF object. For example:

 CFStringRef cf_string = (__bridge_retained CFStringRef)someNSString; // some long time later, perhaps in another method etc CFRelease(cf_string); 

So __bridge_retained really tells the compiler that you have an ARC object, and now you want to basically turn it into a CF object that you are going to manage directly.

+12
source

All Articles