views:

40

answers:

2

I am looking for some reference work or tutorial of a persistent objective-c tree? I am trying to build a family tree (genealogy records) app on iPhone / Mac OS. Thanks!

A: 

Your question is not very clear. You can define any type of data model that you want. If you want to build objects that can have a parent and children you just build it.

What have you tried that has not worked? How did it not work?

Marcus S. Zarra
What I am looking for is: a c tree is saved via Core Data api when the app quits; and builds the tree when the app restarts. Objective c + Core Data. Thanks
ohho
You need to read up on Core Data and study the examples. You are asking a very vague question when the answer is most likely trivial. A C-tree is just a basic data model which you can build easily in Core Data. Try to build it then ask questions if you get stuck.
Marcus S. Zarra
@Marcus, any recommended book/doc/article? I am familiar of building a tree in c in serialize it in disk. However, I am not sure which Cocoa built-in structure (NSArray?) to use or to build my own...
ohho
+1  A: 

(key: --> = to-one, -->> = to-many)

Your basic tree-like entity map would look like this:

LinkedTreeNode{
    //... whatever attributes you want a node to have
    parent <--(optional,nullify)-->>LinkedTreeNode.children
    children <<--(optional, cascade)-->LinkedTreeNode.parent
}

It has one entity that has relationships to itself. The parent relationship points to one other object above it in the tree (the parent) and to one or more child objects below it in the tree. Its logically exactly like a standard C tree. You simply replace pointers that serve as links with entity graph relationships.

For modeling genealogy relationships, you need to add a spouse because (hopefully) every person as a father and mother and any person may have more than one spouse.

Person{
    spouses <<--(optional,nullify)-->>Person.spouses
    parents <<--(optional,nullify,Max=2)-->>Person.children
    children <<--(optional,cascade)-->>Person.parents
}
TechZen