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!
(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
}
精彩评论