Bridge cast required, inconsistent warning when trying to use CGPathRef

I was just setting a property CABasicAnimationfor shadowPath, and I was curious:

shadowAnimation.toValue = (id)newShadowPath.CGPath;

[note: shadowAnimation is an object CABasicAnimation, and newShadowPathan object UIBezierPath]

this works and no error / warning is displayed in Xcode. However, if I write like this:

CGPathRef test = newShadowPath.CGPath;
shadowAnimation.toValue = (id)test;

This will not compile throwing this warning message:

Cast of C pointer type 'CGPathRef' (aka 'const struct CGPath *') to Objective-C pointer type 'id' requires a bridged cast

So I need to enter it like this:

shadowAnimation.toValue = (__bridge id)test;

Now why is this so? Why don't I get the same error in the first example when I use only (id) newShadowPath.CGPath ;? Would it be correct to post there __bridgeregardless of whether Xcode has detected any problems? Or am I missing the difference here?

+5
2

( ) , clang 3.1.

:

@@interface Foo : NSObject
+ (CGPathRef)bar;
@end

CGPathRef foo();

void test()
{
    // works without bridged cast:
    id a = (id)[Foo bar];

    // needs bridged cast
    id b = (__bridge id)foo();
}

, , . .

, ARC C ( Core Foundation).

3.3.2 ARC ( " " ) :

, r C [...] [...]

- [...] __bridge

, C , clang . , , C:

CGPathRef foo() __attribute__((cf_returns_not_retained));

: . , ARC __bridge cast ( __bridge_transfer . __bridge, ).

+2

ARC , .

CGPathRef test , ARC , CoreBlank, .

, id -typed, LLVM freaks , , , start ( __bridge).

, , , ARC , ARC, , ARC.

+2
source

All Articles