Basic Core Data "key" questions

Discussion in 'iOS Programming' started by icewing, Sep 7, 2010.

  1. icewing macrumors 6502

    Jun 19, 2008
    St Louis
    Noob warning!

    I've been programming in a relational database (IBM iSeries/AS400 and RPG) since...wait for it...1979. :eek:

    Trying to wrap my head around Core Data, specifically regarding relationships.

    What I'm trying to do is come up with a tableview, that shows a list of folders and tasks, for example:

    Home Stuff (folder)
    -Pond (folder)
    ----finish waterfall (task)
    ----buy a UV light (task)
    -Office (folder)
    ----clean up desk (task)
    ----move desk to office (task)
    Work stuff (folder)
    -Customer project (folder)
    ----Enhancement 1 (folder)
    --------fix logging issue (task)
    --------add yada yada (task)
    ----Office (folder)
    --------uh nuther task (task)

    With RPG, I would typically define 2 files, one called Folders, and another called Tasks, and define a relationship between them. On the iSeries, I would have a field in each file that would be a unique key...for example, if I wanted 2 folders, both called "Office" at different levels, so there would be no confusion between them.

    Should I have a "hidden" field that would be a unique key, that the relationships are based on, for example a timestamp field that would be have an automatically generated value when the Folder or Task was created?

    Or am I missing something here?

    Thanks in advance for helping an old programmer try to improve himself!
  2. Luke Redpath macrumors 6502a

    Nov 9, 2007
    Colchester, UK
    It's best if you try not to think of Core Data as a database. The fact that it can use one for persistence is an implementation detail. It's really just a persistent object store

    Core Data will generate it's own unique object IDs so there is no need to add your own unless it has some meaning in your domain.

    Having defined your relationship between Folder and Task,you would simply create a task and add it to the appropriate folder object's tasks collection and update the managed object context. You can have two tasks with the same name. Core Data will know which one is which.
  3. icewing thread starter macrumors 6502

    Jun 19, 2008
    St Louis
    Thanks, Luke! Now on to figuring out sorting and showing/hiding. I'm planning on allowing the user to tap a folder to expand or hide it's entries, wondering how that will work if they tap the disclosure button to drill into it, and then show/hide from that view...onward and upward.

    Thanks again for the help!

Share This Page