ARC + return of autoreleased CFType
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