Hi all,
I've currently created a feedback app which saves the data in .json format to the sandbox of my app.
I'm trying to find a way that I can display the list of these saved documents with the options to either delete them or email them.
I've seen a few people use documet picker but that seams to be only for external documents and not the ones in the sandbox.
I'm currently saving each of the documents with the date and time so i know what file is the newest ect. I then get the file URL's and save them to what i think is an array. Is there a way to view this in a swiftUI view?
Or should i be looking at doing something completely different.
func save() {
let filename = "answers-\(answers.date.timeIntervalSince1970).json"
let jsonAnswer = answers.json!
if let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
do {
let fullPathName = url.appendingPathComponent(filename)
#if DEBUG
print("Full path: \(fullPathName)")
#endif
try jsonAnswer.write(to: fullPathName)
} catch {
print("Error writing data: \(error.localizedDescription)")
}
} else {
print("Error opeining file manager.")
}
// save file list
let fileManager = FileManager.default
let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
do {
let fileURLs = try fileManager.contentsOfDirectory(at: documentsURL, includingPropertiesForKeys: nil)
// process files
#if DEBUG
print("files: \(fileURLs)")
#endif
} catch {
print("Error while enumerating files \(documentsURL.path): \(error.localizedDescription)")
}
}
Thanks for the help!
I only started using swift three weeks ago :)
SOLVED: Needed to append files to the variable so that it would update correctly
for file in files {
self.files.append(UrlFile(name: file.description))
}