So, i've found something about this in Apple Guidelines:
Use the "do not back up" attribute for specifying files that should
remain on device, even in low storage situations. Use this attribute
with data that can be recreated but needs to persist even in low
storage situations for proper functioning of your app or because
customers expect it to be available during offline use. This attribute
works on marked files regardless of what directory they are in,
including the Documents directory. These files will not be purged and
will not be included in the user's iCloud or iTunes backup. Because
these files do use on-device storage space, your app is responsible
for monitoring and purging these files periodically.
I wrote simple function for this:
func setExludedFromBackup() {
var url = try? FileManager.default.url(
for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true).appendingPathComponent("MyFolder")
var resuorceValues = URLResourceValues()
resuorceValues.isExcludedFromBackup = true
try? url?.setResourceValues(resuorceValues)
// print(try? url?.resourceValues(forKeys: [.isExcludedFromBackupKey]).isExcludedFromBackup)
// you can check if your directory excluded from backup (it excluded if "Optional(Optional(true))" printed)
}
Yes, it's Documents folder, because other folders still continue to be cleared.
You simply call this func somewhere (i've used AppDelegate), and check if directory is already excluded from backup before calling it. That protect "MyFolder" in Documents directory from deleting, if iOS has ran out of memory! So my data will be available as long as i want to. But you must include after-time deleting mechanism too, because this data will never be deleted automatically and on-device memory space will not be released. In my case i just used Cache framework's expiry
property
P.S. Im not sure how will Apple react to this, while inspecting your app for AppStore, so tell them about offline use in your app and what you did with documents folder, don't forget to describe your deleting mechanism. I hope that doesn't break Apple Guidelines and app will not be rejected.