简体   繁体   中英

Why should I not store data as files on iOS?

If I have a collection of around 100 entities that I need to store, each with a few KB of data, what problems could I encounter if I were to choose to save and read them as files, instead of using Core Data or sqlite or any other database?

I'll most likely need to use only a few at a time, and I plan on reading, parsing and loading them in memory, using them, then releasing them when they are of no more use. Also, I'll never need to search for data inside them and I'll always access them by their ID.

What database offers you is representing relationship between pieces of data, integrity maintenance, transactional support, and indexing for fast searching and access. (Well, all that and a bit more...)

On the flip side, databases are notoriously inefficient when you have to deal with non-structured or non-uniform data - binary blobs like images, XML files each with different loosely defined schema, and so on. Hence why nobody uses relational databases for caching purposes, for example.

So, whether you should use Core Data (or another database) or files depends really on the content of these files, what their relationship is, and what you need to do with them.

It's perfectly fine to embed lot's of files - I suspect the file system to be pretty efficient. If you need to access or filter them on some attributes, or read data partially, or do other fancy things with them, this is where a database comes in handy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM