2

I'm storing image files in Documents directory for file caching.

var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
var path = paths.stringByAppendingPathComponent(imagePath!)
data.writeToFile(path, atomically: true)

What will happen when so many file stored? Is there auto swapping? Or can i detect it with code?

NOTE: I don't want to use tmp directory.

Daedelus
  • 266
  • 5
  • 14
  • What do you mean by Auto Swapping? With which file/image you want the swap to take place? I believe you are looking for some mechanism to delete those files after some time interval. Am i right? – Gandalf Oct 25 '14 at 11:32
  • Yeah, deleting files after some time interval prevents bad usage of storage. – Daedelus Oct 25 '14 at 11:41
  • 2
    Nothing in the documents directory would get deleted automatically. There are other directories, like cache directory, temporary directory, for that purposes. On the other hand, things could get deleted there very quickly. I think instead of looking for the technical details, you should first figure out what you want. – gnasher729 Oct 25 '14 at 11:58
  • As i said don't want to use temp directory. It's cleaning when app closed. But i can try cache directory for that purpose. – Daedelus Oct 25 '14 at 12:01

2 Answers2

3

That's what i want. Thanks @gnasher729.

Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.

Daedelus
  • 266
  • 5
  • 14
0

There is no Auto Swipe mechanism to handle such task. It's user data and user should have control over it, when to write and when to delete. You can program such task within application. You need to decide if you want
1. To keep a check based upon no of days from file creation or
2. To keep a check on no of maximum files that are allowed within directory.

You can run this task in background every time while launching the application .

You can delete individual files using below code. Check this Question

[[NSFileManager defaultManager] removeItemAtPath: pathToFile error: &error];

Note - I recommend going through iOS Data Storage Guidelines to figure out which directory will suit you better

Community
  • 1
  • 1
Gandalf
  • 2,399
  • 2
  • 15
  • 19