I am using Swift 4, and I need to know how to delete using UIDocument. I know how to set up the url path:
if let url = try? FileManager.default.url(
for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true
).appendingPathComponent("Inbox/test.txt") {
falloutFileHandler = FalloutTextFileHandler(fileURL: url)
}
where falloutFileHandler is of type UIDocument, and falloutFileHandler has a property called falloutFile which stores the string as a property called 'data'.
And I know how to open the file:
falloutFileHandler?.open { success in
if success {
if let theText = self.falloutFileHandler?.falloutFile?.data {
self.textView.text = self.text!
} else {
print("Something went wrong")
}
}
}
But I do not know how to delete a file using UIDocument. Thank you in advance.
Also, is there a way to print out why something isn't successful in opening? Such as print(error) or something like that instead of doing what I did which was print("Something went wrong")?