Reputation: 2508
I have a Core Data entity which needs a gender property. I just need one of two, the standard male or female values. What's the best practice for this in Core Data?
In the .NET world with databases I would've created a Gender table, with foreign key in the child table. I'm still getting my head around Core Data right now - any suggestions would be greatly appreciated.
Cheers, Dany.
UPDATE
Based on the comments here I have added an extra NSString property in my Core Data entity called gender
. Its getter and setter manipulate the isMale
property value. The UI is bound to gender
- works a treat so far! Thanks for the help everyone.
Upvotes: 0
Views: 617
Reputation: 46718
I would not do a look up as Core Data is not a database but rather an object hierarchy that happens to persist to a database.
Instead I would have a boolean called male
with a getter accessor -isMale
since there is no risk of there ever being a third.
Despite the commentary, how you interact on the UI is completely separate from how you store the data. How you display is up to your UI design. The code in your controller will handle the translation between the boolean state and the UI display.
You can have a checkbox, radio buttons, drop down list, et. al.; doesn't matter. Just translate what the user interacts with in your controller.
Upvotes: 1