Well, first you have to know if you are using ARC or not, because the rules change a bit. Next, you need to know what you actually want to do with your cast. Do you just want to use the value, or transfer ownership?
I will assume ARC, because, IMO, all new code really should be using ARC (and ARC is where the casting problems are more prevalent).
CFArrayRef someArrayRef = ...;
NSArray *array = (__bridge NSArray*)someArrayRef;
The above code casts the CF reference to an NSArray*
that can be used in the current context. No transfer of ownership has taken place. someArrayRef
still holds its reference, and you still must manually release someArrayRef
or it will leak.
CFArrayRef someArrayRef = ...;
NSArray *array = CFBridgingRelease(someArrayRef);
In this code, you not only get a cast, but a transfer of ownership. someArrayRef
now no longer holds the reference, so it does not need to be manually released. Instead, when array
releases, the object will dealloc (assuming no other references in other places).