Class
NavigatorTree
A NavigatorTree is a class holding information about a tree of data that can be navigated using a tree navigator.
class NavigatorTree
Discussion
A tree is a data structure containing a number of nodes equal or greater than 1. Each node can have multiple children, but only one parent and assigning the same node as children of multiple nodes results in a broken data structure. There’s no validation when adding a node as children to another node.
A tree can get serialized to the disk using the following structure:
┌──────────────┬──────────────┬──────────────────────┐
│ parentID │ objectLength │ object │
│ UInt32 │ UInt32 │ Data │
│ (4 bytes) │ (4 bytes) │ (variable size) │
└──────────────┴──────────────┴──────────────────────┘
The object needs to be conforming to Serializable so it can be transformed to raw data and reconstructed back using the same one.
Note
The parentID might be missing if the object is the root, but to avoid creating an exception on the object structure, its id is set to 0.
Topics
Classes
Initializers
Instance Properties
Instance Methods
func read(from: URL, bundleIdentifier: String?, timeout: TimeInterval, delay: TimeInterval, queue: DispatchQueue, presentationIdentifier: String?, broadcast: NavigatorTree.BroadcastCallback?) throwsRead a tree from disk from a given path. The read is atomically performed, which means it reads all the content of the file from the disk and process the tree from loaded data.
func write(to: URL, writePaths: Bool, callback: ((NavigatorTree.Node) -> ())?) throwsSerialize the node and descendants to the disk. Every node is written in order using a breath first approach, assigning to each node a virtual identifier in UInt32 which is then used to identify the parent. The initial index is 0 and the root gets id 0 and parent id 0, so it can be easily recognized inside the serialized data and it’s expected to be the first element.
Type Aliases
Type Methods
Enumerations