Core Data vs NSFileManager
core-data, ios, nsfilemanager, objective-c
Solution
Core Data is worth using in every scenario you described. In fact, if an app stores more than preferences, you should probably use Core Data. Here are some reasons, among which, you'll find answers to your own problems:
- is definitely faster than the filesystem, even if you wipe out everything and write it again as you describe (so you don't benefit to much from caching). This is basically because you can coalesce your operations and only access the store when needed. So if you read, write and read, you can save only once, the rest is done in memory, which is, needless to say, very fast.
- everything is versioned and you can migrate from one version to another easily (while keeping the content the user has on the device)
- 80% of your model operations come free. Like, when something changes, you can override the `willSave` managed object method and notify your controllers.
- using `cascade` makes it trivial to delete even very complex object structures
- while is a bad idea to keep images in the database, you can still keep them on the filesystem and have core data delete them automatically when the managed object that represents them is deleted
- is flexible, in fact is so flexible that you could migrate your project from using the local filesystem to using a server with very little modifications by writing a custom data store.
- the core data designer basically creates the model objects for you. You don't need to create your own model classes (which you would have to if using the filesystem)
Problem
The problem: I have been using for some time now my own cache system by using `NSFileManager`. Normally the data I receive is JSON and I just save the dictionary directly into cache (in the Documents Folder). When I need it back I will just go get it. I also implement, sometimes when I feel it's better, a `NSDictionary` on the root Folder with keys/values for the path for a given resource. For example: Resource about weather in Geneve 17/02/2013, so I would have a key called GE_17_02_2013 and the value the path to the `NSDictionary` with the information. Normally I don't need to do any complex queries. But, somehow, and from what I have been reading, when you have a lot of data, you should stick with Core Data. In my case, I normally have a lot of data, but I never actually felt the application going down, or suffering in terms of performance. So my questions are: In this case, where sometimes (the weather thing was just an example) I need to just remove all the data (a Twitter feed, for example) and replace it by a completely new stream of data, is Core Data worth? I think removing all the data, and inserting (populating) it, is heavier than just store the `NSDictionary` and replacing the old one. Sometimes it would envolve images, textFiles, etc and the `NSFileManager` does it perfectly, so what advantages could Core Data bring in this cases? P.S: I just saw this post, where this kind of question is made and numbers prove which one is actually faster. Still, I would like as well an empiric answer.