开发者

Creating "lookup" values in Core Data

I have a Core Data entity wh开发者_Go百科ich 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.


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.

update

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜