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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:03:46+00:00 2026-05-25T17:03:46+00:00

I’m working on a project which would be ideally suit Cocoa bindings for the

  • 0

I’m working on a project which would be ideally suit Cocoa bindings for the UI but I’m having an issue binding the value of an object property and can’t find a suitable solution. The object is as follows:

typedef enum tagCSQuality {
    kQualityBest            = 0,
    kQualityWorst           = 1
} CSQuality;

@interface CSProfile : NSObject {
   NSString *identifier;
   NSString *name;
   CSQuality quality;
}

In the XIB, I have an object controller whose content object is bound to a “currentSelection” property of the window controller which is an instance of the above object. I’ve then bound the name and identifier which all work as expected but I cannot see how I can bind the enums.

Ideally I would like an NSPopupButton to display “Best” and “Worst” and pick the correct enum value. I have updated the enum to have an explicit numeric value and I believe that I need a value transformer to convert the values but I’m stuck on exactly how this could be implemented.

Can anyone help me out or point me in the right direction?

Thanks,
J

  • 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-25T17:03:47+00:00Added an answer on May 25, 2026 at 5:03 pm

    You can use an NSValueTransformerfor this.

    Since the enumeration values are integers only, they are encapsulated in an NSNumber object.

    An valid transformer could look like the following.

    +(Class)transformedValueClass {
        return [NSString class];
    }
    
    -(id)transformedValue:(id)value {
        CSQuality quality = [value intValue];
        if (quality == kQualityBest)
            return @"Best";
        else if (quality == kQualityWorst)
            return @"Worst";
    
        return nil;
    }
    

    This can be bound to the Selected Value binding of the NSPopupButton.

    If you want to create a bidirectional binding (i.e. be able to select something in the NSPopupButton you have to add the following code for the reverse transformation:

    +(BOOL)allowsReverseTransformation {
        return YES;
    }
    
    -(id)reverseTransformedValue:(id)value {
        if ([@"Worst" isEqualToString:value]) 
            return [NSNumber numberWithInt: kQualityWorst];
        else if ([@"Best" isEqualToString:value]) 
            return [NSNumber numberWithInt: kQualityBest];
    
        return nil;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.