0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

シミュレーターのローカルにデータを保存する

Posted at
        do {
            let fileManager = FileManager.default
            let docs = try fileManager.url(for: .documentDirectory,
                                           in: .userDomainMask,
                                           appropriateFor: nil, create: false)
            let path = docs.appendingPathComponent("myFile.txt")
            let data = "Hello, world!".data(using: .utf8)!

            fileManager.createFile(atPath: path.path,
                                   contents: data, attributes: nil)
            let documentDirPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
            print(documentDirPath)

        } catch {
            print(error)
        }

上記はコピペでオッケーです。
また配置場所はドキュメント配下に置いてます。

イメージはこんな感じ。

スクリーンショット 2021-04-19 15.00.12.png

printのやり方はiOS シミュレーターのフォルダの場所をprintしたいをみてください。

0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?