Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6386185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:59:33+00:00 2026-05-25T02:59:33+00:00

With ARC, I can no longer cast CGColorRef to id . I learned that

  • 0

With ARC, I can no longer cast CGColorRef to id. I learned that I need to do a bridged cast. According clang docs:

A bridged cast is a C-style cast annotated with one of three keywords:

(__bridge T) op casts the operand to the destination type T. If T
is a retainable object pointer type, then op must have a
non-retainable pointer type. If T is a non-retainable pointer type,
then op must have a retainable object pointer type. Otherwise the cast
is ill-formed. There is no transfer of ownership, and ARC inserts no
retain operations.

(__bridge_retained T) op casts the operand, which must have
retainable object pointer type, to the destination type, which must be
a non-retainable pointer type. ARC retains the value, subject to the
usual optimizations on local values, and the recipient is responsible
for balancing that +1.

(__bridge_transfer T) op casts the operand, which must have
non-retainable pointer type, to the destination type, which must be a
retainable object pointer type. ARC will release the value at the end
of the enclosing full-expression, subject to the usual optimizations
on local values.

These casts are required in order to transfer objects in and out of
ARC control; see the rationale in the section on conversion of
retainable object pointers.

Using a __bridge_retained or __bridge_transfer cast purely to convince
ARC to emit an unbalanced retain or release, respectively, is poor
form.

In what kind of situations would I use each?

For example, CAGradientLayer has a colors property which accepts an array of CGColorRefs. My guess is that I should use __brige here, but exactly why I should (or should not) is unclear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:59:34+00:00Added an answer on May 25, 2026 at 2:59 am

    I agree that the description is confusing. Since I just grasped them, I’ll try to summarize:

    • (__bridge_transfer <NSType>) op or alternatively CFBridgingRelease(op) is used to consume a retain-count of a CFTypeRef while transferring it over to ARC. This could also be represented by id someObj = (__bridge <NSType>) op; CFRelease(op);

    • (__bridge_retained <CFType>) op or alternatively CFBridgingRetain(op) is used to hand an NSObject over to CF-land while giving it a +1 retain count. You should handle a CFTypeRef you create this way the same as you would handle a result of CFStringCreateCopy(). This could also be represented by CFRetain((__bridge CFType)op); CFTypeRef someTypeRef = (__bridge CFType)op;

    • __bridge just casts between pointer-land and Objective-C object-land. If you have no inclination to use the conversions above, use this one.

    Maybe this is helpful. Myself, I prefer the CFBridging… macros quite a bit over the plain casts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a strange exception in Xcode 4.2.1 (ARC-enabled project) that I can't track
I'm aware that you can set the compiler flag -fno-objc-arc to disable Automatic Reference
My project using ARC, so I can't use retain nor release, in ViewController A,
What is the lowest iOS version I can build for while using (ARC)? I'm
I want to transition my App to ARC . I can change Objective-C Automatic
With ARC sometimes I still need to write a -dealloc method to do some
I am refactoring to use ARC in my project and can not figure out
I’m working in a pure iOS5/ARC environment, so I can use __weak references as
I understand that CGAffineTransformMakeRotation can rotate an image, and CGAffineTransformMakeTranslation translates an image. I
Is there a list of classes in iOS that can't be referred with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.