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 4599870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:36:10+00:00 2026-05-21T23:36:10+00:00

I’m using Opacity to generate all my Quartz2D artwork and I’m now tackling the

  • 0

I’m using Opacity to generate all my Quartz2D artwork and I’m now tackling the issue of changing colours via KVC/KVO. Opacity defines all its colour variables as @dynamic and implements its own accessors as part of the class definition.

My question is; how do I pass a new CGColorRef value by key value?

So far (as a testbed) I’ve got this far:

// Testbed ... Testbed ... Testbed ... Testbed ... Testbed ... Testbed ... Testbed ...
      CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
      CGFloat components[4] = {1.0f, 1.0f, 1.0f, 1.0f};
      CGColorRef color = CGColorCreate(space, components);

      [myCALayerReceiverObject setValue: color forKey: @"numColour"];
// Testbed ... Testbed ... Testbed ... Testbed ... Testbed ... Testbed ... Testbed ...

The colour space and creation code is lifted directly from Opacity’s CALayer class generator (I’m not that advanced yet) but passing ‘color’ as the value causes the iPhone simulator to crash and XCode gives me a very cryptic warning;

“Incompatible pointer types sending ‘CGColorRef’ (aka struct ‘CGColor *’) to parameter of type ‘id’ “.

How do I wrap up the CGColorRef to pass it across KVC to the receiver?
Thanks in advance.

  • 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-21T23:36:11+00:00Added an answer on May 21, 2026 at 11:36 pm

    I was going to suggest using NSValue to wrap your color object, but during testing I have come to the conclusion that KVO/KVC will not work with CGColors. According to the Key-Value Coding Programming Guide, primitive types and structures are wrapped using NSValue or NSNumber. However, when trying to access a CGColorRef property, I get a “not KVC compliant” exception. It seems that pointers to structures are not wrapped to NSValues in the same way as the structures themselves. Here is my test code:

    @interface MyClass : NSObject {
        CGColorRef color;
    }
    @property (assign) CGColorRef color;
    @end
    
    @implementation MyClass
    - (CGColorRef)color { return color; }
    - (void)setColor:(CGColorRef)newColor { color = newColor; }
    @end
    
    int main(int argc, char **argv) {
        NSAutoreleasePool *p = [NSAutoreleasePool new];
        MyClass *theObject = [MyClass new];
        CGColorRef theColor = CGColorCreateGenericRGB(1.0,1.0,1.0,1.0);
        theObject.color = theColor; // works
        NSLog(@"%@",[theObject valueForKey:@"color"]); // NSValue expected, actually causes exception
        [p release];
        return 0;
    }
    

    One possible workaround is to add a category to the proper class which defines accessors for a different key. These accessors would be NSValue wrappers for the numColour key.

    // in the category
    - (NSValue *)numColourKVC {
        return [NSValue valueWithPointer:(void*)self.numColour];
    }
    - (void)setNumColourKVC:(NSValue *)newValue {
        self.numColour = (CGColorRef)[newValue pointerValue];
    }
    

    Then you would set the color in your testbed as follows:

    [myCALayerReceiverObject setValue:[NSValue valueWithPointer:(void*)color] forKey:@"numColourKVC"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.