I'm rewriting my app to incorporate SceneKit to display molecules. About 60% of my code is dedicated to creating these molecules as SCNNode
arrays stored in a dictionary. Another 20% creates a String
dictionary for text display. Ideally, these dictionaries need only be created once.
Currently I'm creating these dictionaries by calls from viewDidLoad
in my main (and initial) VC. I then archive the dictionaries:
NSKeyedArchiver.archiveRootObject(moleculeDictionary, toFile: filePath)
I then read the archived dictionary back into a local dictionary that is used by the app:
moleculeDictionary = Molecules.readFile() as! [String: [SCNNode]]
// and in Molecules, the readFile() function:
let dictionary = NSKeyedUnarchiver.unarchiveObjectWithFile(filePath) as? NSDictionary ?? NSDictionary()
return dictionary
I read it from the archive in case the local version is no longer extant. I still need to add a check for the existance of the dictionary.
My question: Is this the best way to do this? Surely this is a common aspect of many programs. My inclination is to create permanent files with these dictionaries during development and include them in the shipped bundle. But no one has responded to my posts on this aspect so I'm thinking everyone does it some other way. I'm praying I don't have to learn about CoreData but if so, let me know.