I have a swiftUI app and it reads from and writes to a CSV file called sythesisedData.csv. Part of this project is trying to have a level of user-privacy, and therefore I want this CSV file to be unreadable if anyone were to try and directly open it from the application bundle.
I have tried doing this (n.b fileUrl points to the synthesisedData.csv file)
try (fileUrl as NSURL).setResourceValue(
URLFileProtection.complete,
forKey: .fileProtectionKey)
But the file when I inspect the bundle in the finder of my Mac is still readable in plain text. I find the csv file by doing .app file -> show package contents -> open the .csv file
.
Does anyone know how to make this file unreadable when opened manually? Obviously my app still needs to be able to read and write from it though.
P.S this file is NOT created by my app, it pre-exists before the app is launched as it is populated with data I need.
You can encrypt your file using wrapper like: https://github.com/RNCryptor/RNCryptor and then write the file to the document directory.