It seems like this is not supported in the Simulator because when I run my Unit tests and I try to read protection key-value the value is always nil, even if I set the data protection level when I write the file.
On device this key returns the expected value.
Is it possible to have the simulator support the data protection classes to run my unit tests?
FYI Im testing on iOS
It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.
Could you try setting something else in your test code?
Oh, hey, would you look at that. I switched to .completeFileProtection
and that reproduced the problem.
I then put the same code in a Mac app and that worked.
I believe this a special case within the simulator. Because macOS previously didn’t support data protection, FileManager
avoids getting and setting these attributes [1].
As to whether this should change, I’m in two minds about that:
-
On the one hand, changes like this often break working code.
-
And it’ll be of limited utility because data protection is primarily relevant when the device is locked, and the simulator doesn’t really support that.
-
OTOH, it’d help folks, like yourself, who are writing new code.
If you have a strong opinion about this, feel free to register it in Feedback Assistant. And if you do file a bug, please post your bug number, just for the record.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Some spelunking in the Foundation open source reveals evidence for my theory. See here.