CGColorCreateGenericRGB Error on iPhone SDK 3.0

by Warlock on May.26, 2009, under Cocoa

While porting some Core Graphics/Quartz 2D code from the Mac to the iPhone, I ran across the following error:

error: 'CGColorCreateGenericRGB' is unavailable (declared at

/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGColor.h:31)

Looking in the header file in question (CGColor.h), I found the following:

/* Create a color in the "Generic" RGB color space. */

CG_EXTERN CGColorRef CGColorCreateGenericRGB(CGFloat red, CGFloat green,
    CGFloat blue, CGFloat alpha)
    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA);

So the header file pretty much confirms what the error says; the function is not available on the iPhone.

After a little bit of looking through documentation, you just have to specify the color space manually and then give the components to the color. So the this:

CGColorCreateGenericRGB(0.90625, 0.80, 0.80, 1.0)

would become


CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
const CGFloat myColor[] = {0.90625, 0.80, 0.80, 1.0};
CGColorCreate(rgb, myColor);
CGColorSpaceRelease(rgb);

:, ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...