LoginSignup
2
1

More than 5 years have passed since last update.

【Swift4】ファイルの削除方法

Posted at

環境

  • X-code 9.4
  • Swift4.1

コード

覚え書き程度ですが。

        // パスを取得
        let libraryPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true).first as String?
        let cookiesPath = libraryPath?.appending("/Cookies")
        let webKitPath = libraryPath?.appending("/WebKit")
        let cachesPath = libraryPath?.appending("/Caches")

        print("------libraryPath:" + libraryPath! + "------")
        print("------cookiesPath:" + cookiesPath! + "------")
        print("------webKitPath:" + webKitPath! + "------")

        // ファイルの削除
        do {
            try FileManager.default.removeItem(atPath: cachesPath!)
            try FileManager.default.removeItem(atPath: cookiesPath!)
            try FileManager.default.removeItem(atPath: webKitPath!)
        } catch {
            // エラー処理
        }
"/Cookies"

とか、文字列なのが、なんとなく、ただなんとなくいけ好かないけれど、
エラーになることなく実行できました。

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1