I have a file structure that looks like this:
I'm using a struct that conforms to the Codable protocol. I want to write it's values to the Root.plist but I don't know how to do this. I read from the Root.plist file like this:
let defaults = UserDefaults.standard.dictionaryRepresentation()
let systemID = defaults["systemID"] as? String ?? "Demo"
I don't want to write to this file one property at a time. This is what I'm trying but it says that the Root.plist doesn't exist.
func writeToSettingsBundle(config: Configuration) {
let encoder = PropertyListEncoder()
encoder.outputFormat = .xml
let path = FileManager.default.urls(for: .applicationDirectory, in: .userDomainMask)[0].appendingPathComponent("Root.plist")
print("path: \(path)")
do {
let data = try encoder.encode(config)
try data.write(to: path)
} catch {
print("Could not encode settings: \(error.localizedDescription)")
}
}
I"m new to iOS.....what am I doing wrong?
