Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does this cast require no bridging under ARC?

Why does casting a CGImageRef to an object pointer require no memory management info (__bridge etc.)? For example, if image is of type UIImage *, and layer is a UIView's underlying layer, then the following line of code does not elicit any complaints from the compiler:

layer.content = (id)[image CGImage];
like image 870
Inept Avatar asked May 01 '12 20:05

Inept


1 Answers

To quote Transitioning to ARC Release Notes:

The Compiler Handles CF Objects Returned From Cocoa Methods

The compiler understands Objective-C methods that return Core Foundation types follow the historical Cocoa naming conventions (see Advanced Memory Management Programming Guide). For example, the compiler knows that, in iOS, the CGColor returned by the CGColor method of UIColor is not owned. You must still use an appropriate type cast, as illustrated by this example...

(OK, not quite cocoa-touch, but hey!).

Because CGImage returns a CoreFoundation object, a __bridge cast isn't required.

like image 156
CodaFi Avatar answered Nov 15 '22 08:11

CodaFi