I am rewriting my application to enable SceneKit to display molecules. About 60% of my code is dedicated to creating these molecules as SCNNode
arrays stored in a dictionary. Another 20% create a dictionary String
for displaying text. Ideally, these dictionaries should be created only once.
I am currently creating these call dictionaries viewDidLoad
in my main (and initial) VC. Then I archive the dictionaries:
NSKeyedArchiver.archiveRootObject(moleculeDictionary, toFile: filePath)
Then I read the archived dictionary back to the local dictionary used by the application:
moleculeDictionary = Molecules.readFile() as! [String: [SCNNode]]
let dictionary = NSKeyedUnarchiver.unarchiveObjectWithFile(filePath) as? NSDictionary ?? NSDictionary()
return dictionary
I read it from the archive if the local version no longer exists. I still need to add a dictionary check.
: ? , . - . , , -. , CoreData, , .