• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Referencing known values in core data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Referencing known values in core data


  • Subject: Re: Referencing known values in core data
  • From: "I. Savant" <email@hidden>
  • Date: Wed, 13 Aug 2008 06:17:02 -0400

On Aug 13, 2008, at 5:34 AM, Andrew Zahra wrote:

I am experimenting with core data. Binding fields such as text fields works
fine. But now I have a pop up menu I want to bind to a set of known values.
I have a "Task" Entity with a "frequency" field. The frequency field is a
set of known values, such as hourly, daily etc, so I have not put this in my
model as a separate entity. What is the correct way to handle this situation
so the value of the popup menu gets saved and loaded from the core data
store?

One way to do this (the way I usually do it) is to:

1 - Define somewhere a lookup list based on numbers.
(example: [NSNumber numberWithInt:1] represents "hourly", 2 is "daily" ...)
2 - In your entity, specify your 'frequency' attribute as one of the integer types.
3 - For each popup that uses this list, create an item for each word (hourly, daily, ...) by hand, setting each item's tag to the number that represents that item.
(example: set the "hourly" item's tag to "1")
4 - Bind the popup's "selectedTag" to your Task entity's 'frequency' attribute via some controller.


That's it. You may wonder why I don't just suggest using the 'selectedIndex' binding. Simple: you may some day want to insert "weekly" between "daily" and "monthly". That would cause problems with existing user data since the indices would change. Via the tag method, you can reorder / insert menu items at will.

--
I.S.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Referencing known values in core data (From: "Andrew Zahra" <email@hidden>)

  • Prev by Date: Referencing known values in core data
  • Next by Date: Re: DICOM images in Cocoa
  • Previous by thread: Referencing known values in core data
  • Next by thread: Programmatically place cursor within NSTextField
  • Index(es):
    • Date
    • Thread