对于我的mac应用程序(在swift中),我目前通过编写&读取.txt文件。为了使文件看起来更专业,我如何用以下文件编写文件:
编辑:这是我目前使用的(不是很有用):
let root = XMLElement(name: "root")
let xml = XMLDocument(rootElement: root)
root.addChild(XMLElement(name: "value", stringValue: "125"))
root.addChild(XMLElement(name: "key", stringValue: "kF15304g3DlJkR"))
let fileName = "File"
let directory = try? FileManager.default.url(for: .desktopDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
if var fileURL = directory?.appendingPathComponent(fileName).appendingPathExtension("xml") {
do {
try xml.xmlString.write(to: fileURL, atomically: true, encoding: .utf8)
} catch {
print(error.localizedDescription)
}
do {
var resourceValues = URLResourceValues()
resourceValues.hasHiddenExtension = true
//resourceValues.thumbnail is get-only!?!? :( how do I set it?
try fileURL.setResourceValues(resourceValues)
} catch {
print(error.localizedDescription)
}
}