更新.txt文件中的文本不会迅速生效

时间:2019-04-03 07:11:53

标签: ios swift

我的项目中有一个.txt文件,其中包含一些内容。

我正在尝试通过提供文件的路径来更改其中的内容

打印路径并检查文件,内容正在更新,但未反映项目文件夹中的文件。

如何在.txt文件中实现项目效果并更改内容

    let fileContentToWrite = "Tele sdmsjdnf  vcf sjnfkjwnjs"

    let filePath = Bundle.main.url(forResource: "Files", withExtension: "txt")
    do {
        // Write contents to file
        try fileContentToWrite.write(to: filePath!, atomically: false, encoding: String.Encoding.utf8)
    }
    catch let error as NSError {
        print("An error took place: \(error)")
    }


    // Read file content.
    do {
        // Read file content
        let contentFromFile = try NSString(contentsOfFile: fileURL!.path
            , encoding: String.Encoding.utf8.rawValue)
        print(contentFromFile)
    }
    catch let error as NSError {
        print("An error took place: \(error)")
    }

当尝试打开其中包含的Files.txt文件时,项目文件夹不会影响已进行的更改。

如何在项目文件夹中包含的文件中进行修改?

0 个答案:

没有答案