ios – Retailer file to documentDirectory with out person interplay


So presently I’ve an app the place the person can retailer a json file within the Shortcuts folder on the gadget. The present code I’m operating appears to be like like this:

func saveDataToDocuments(_ information: Information, jsonFilename: String = "Userfile.JSON") {

    let jsonFileURL = getDocumentsDirectory().appendingPathComponent(jsonFilename)
    do {
        strive information.write(to: jsonFileURL)
        let directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
        strive? information.write(to: jsonFileURL)
        let exportMenu = UIDocumentPickerViewController(url: jsonFileURL, in: .exportToService)
        exportMenu.delegate = self
        exportMenu.modalPresentationStyle = .formSheet
        current(exportMenu, animated: true)
    } catch {
        print("Error:= (error.localizedDescription)")

func getDocumentsDirectory() -> URL {
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    let documentsDirectory = paths[0]
    return documentsDirectory

The file is created and accommodates information the the person create within the app, and every time the person edit the information, he/she has to manually save the file once more. So what I’m asking is: Is it doable to make a perform that after the person has saved the file one time, the person can now simply faucet a button “Replace file”, and the file get’s saved and changed routinely within the background, with out the utilizing having to open up the UIDocumentPickerViewController and faucet Archive?


Leave a Reply