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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:01:40+00:00 2026-06-05T08:01:40+00:00

I have a NSView subclass that I want to expose a property (an NSGradient

  • 0

I have a NSView subclass that I want to expose a property (an NSGradient, to be exact) so I can bind it with other object (programatically using the bind:toObject:withKeyPath:options: method).

What steps should I take?

Here’s what I done:

+(void)initalize {
  [self exposeBinding:@"gradient"];
}
- (Class)valueClassForBinding:(NSString*)binding {
  if ([binding isEqualToString:@"gradient"]) { return([NSGradient class]); }

  return(nil);
}
-(NSArray*)exposedBindings {
  return([NSArray arrayWithObjects:@"gradient",nil]);
}

I don’t mind if the binding does not show in the Interface Builder.
The gradient is a property implemented with @property (nonatomic, retain) NSGradient* gradient and it’s working fine with the current implementation.

Is JUST the above code needed to implement that? (It seems too easy)
I believe I’m missing something.

Note: I’m not a Bindings expert, but I do well on most of Objective-C.

  • 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-06-05T08:01:44+00:00Added an answer on June 5, 2026 at 8:01 am

    The property to be bounded must be KVO and KVC compliant; that’s in essence all that’s necessary. Declaring the property the way you do and then @synthesizeing them or doing something equivalent is enough.

    bind:toObject:withKeyPath:options: is for some reason only one way, so you’ll have to propagate values using KVC as Tom Dalling notes. Changes made on the receiver of the -bind:etc message have to be propagated manually.

    To my knowledge -exposeBinding: doesn’t really do anything in Xcode 4 and is not necessary as IB no longer supports plugins. From the documentation:

    In most cases you need to use bind:toObject:withKeyPath:options:, and
    then only when you establish bindings programatically. Use of the
    unbind: is discussed in “Unbinding.” The other methods—the class
    method exposeBinding: and the instance methods exposedBindings and
    valueClassForBinding:—are useful only in an Interface Builder palette.

    To my knowledge the majority of the code you posted isn’t necessary as long as you used -bind:toObject:withKeyPath:options:. You would keep that code to expose the binding in Interface Builder, but since we’re in 2012 now and IB no longer has plugins…

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

Sidebar

Related Questions

I have drawn an object on NSView subclass. How can the object know that
I have a custom NSView subclass that I want to animate with Core Animation.
What I want to do I have a circular custom NSView subclass, and I
I've got a custom NSView subclass which I want to have rounded corners. I
I have an NSView subclass that gets initialized with an OpenGL context and has
I have a subclass of NSView where I'm handling the -mouseDown: event to get
I have a window with an subclass of NSView in it. Inside the view,
I have an NSView in which the user can draw circles. These circles are
Here's the scenario - I have created a custom NSView subclass, and the implementation
I am writing a simple MacRuby app. I have an NSView that draws an

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.