• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
ARC + return of autoreleased CFType
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ARC + return of autoreleased CFType


  • Subject: ARC + return of autoreleased CFType
  • From: John Pannell <email@hidden>
  • Date: Wed, 19 Oct 2011 07:04:24 -0600

Hi all-

I've got a category on NSColor to return a CGColor value.  Source looks like this:

- (CGColorRef)CGColor
{
    NSColor *colorRGB = [self colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
    CGFloat components[4];
    [colorRGB getRed:&components[0] green:&components[1] blue:&components[2] alpha:&components[3]];
    CGColorSpaceRef theColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    CGColorRef theColor = CGColorCreate(theColorSpace, components);
    CGColorSpaceRelease(theColorSpace);
    return theColor;
}

My issue is with the final line: the CGColor has a retain count of 1, as it was made with a "Create" function.  Following Cocoa convention, I'd want to cast the return value and autorelease it, but the autorelease call is not allowed under ARC.  Xcode is doing its best to help me figure out how to return the value, but the only thing I can get it to not squeak about is this:

return (__bridge_retained CGColorRef)(__bridge_transfer id)theColor;

which does not seem reasonable to me.  Can anyone suggest the proper syntax to return an "autoreleased" CGColorRef from this function?

Thanks!

John


John Pannell
http://www.positivespinmedia.com_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: ARC + return of autoreleased CFType
      • From: Ken Thomases <email@hidden>
    • Re: ARC + return of autoreleased CFType
      • From: Roland King <email@hidden>
  • Prev by Date: Re: How to get key code from "SysDefined" Carbon Event
  • Next by Date: Re: ARC + return of autoreleased CFType
  • Previous by thread: Source list groups hidden by default
  • Next by thread: Re: ARC + return of autoreleased CFType
  • Index(es):
    • Date
    • Thread