I have a simple core-data entity that has a Boolean attribute called subscribedToNewsletter
. I have designed my UI to represent this field as a radio button group with Yes
/No
as the text values (and obviously YES
/NO
as the backing BOOL values).
I have always considered myself to have excellent google-fu, but for the life of me, I am unable to find any clear documentation on:
- how to bind the selected value of the NSMatrix (or is it the cell?) back to a YES/NO value
- how to bind the textual values (if indeed I do need to; I know there are only ever going to be two values - surely they can be hard-coded in Interface Builder, or not?)
Next up will be how to bind a radio group (with Male/Female
text) to a String field called gender
that has M
and F
as possible values - but I digress.
Any pointers would be very much appreciated. Thanks a lot.
Not sure if I got no answers because a) it is such a stupid question, or b) no-one in the world knows how. The latter doesn't strike me as likely, so I can only presume the first :)
Anyway just in case there others as stupid as me, I thought I'd give some feedback on how I managed to achieve it.
In Interface Builder, I created a NSMatrix with two radio button cells with "Yes" and "No" as the text for each respectively. In the Attributes Inspector (command-1), make sure the Tag field is set to 1 for the "Yes" button cell, and set to 0 for the "No" button cell. Then, in the Bindings Inspector (command-4) bind the SelectedTag field for the matrix to the Boolean property on your entity. Easy as pie.
I make no claims that this is the best way... just that it is effective.