MASTG-KNOW-0091 ファイルシステム API (File System APIs)

FileManager インタフェースはファイルシステムの内容を確認および変更できます。createFile(atPath:contents:attributes:) を使用して、ファイルを作成して書き込みを行うことができます。

以下の例は、アプリのドキュメントディレクトリにファイルを完全に保護して保存する方法を示しています。つまり、ファイルは暗号化され、デバイスがロック解除されている場合にのみアクセスできます。

FileManager.default.createFile(
    atPath: filePath,
    contents: "secret text".data(using: .utf8),
    attributes: [FileAttributeKey.protectionKey: FileProtectionType.complete]
)

詳細については Apple 開発者ドキュメント "Encrypting Your App's Files" をご覧ください。

Last updated

Was this helpful?