Original blog, reproduced please indicate the source
Blog.csdn.net/hello_hwc
Welcome to my iOS SDK detailed column
Http://blog.csdn.net/column/details/huangwenchen-ios-sdk.html
Objective:
- CoreData is not a db, nor is it a DBMS, it is an object graph management tool, and its underlying storage uses sqlite,xml or something else. Third-party libraries, such as Magicalrecord, are often used when using CoreData.
- SQLite is a DB, has its own DB Engine, the development of the time directly using SQL statements to operate, the actual development usually use a third-party library, such as Fmdb
This article is more like a collation, sorting out some of the ideas I think and other Google, for your reference, all the reference to the end of the section I will be listed in the reference link.
Respective pros and cons (impossible to fully cover, with the reader seeing what can be added)
I am more familiar with CoreData, SQLite is relatively close, so here CoreData may write a little more.
Advantages of CoreData
- Object Graph Management
- Support for lazy loading (faulting and uniquing)
- Object-oriented programming, intuitive and easy to use
- Good multithreading support (note not thread-safe)
- Support for Redo and undo
- Nsfetchedresultcontroller makes it easy to combine programming with TableView
- KVC and KVO Support
- Icould's support
- Apple's recommended storage, APIs are constantly being upgraded
Disadvantages of CoreData
- High learning costs, long enough to be handy
- Data migration is tricky (and of course, supported) when the object schema changes
- Low efficiency for a large number of update deletions (because it is first taken into memory each time)
- Support for primary keys is maintained on its own (CoreData is the only object to be determined by Objectid)
- Memory consumption is higher (in order to maintain managedcontext, in order to keep track of object changes)
Benefits of using SQLite directly
- The cost of learning is relatively low (there are not so many classes to learn, often computer or software background of children's shoes have some database knowledge, using some SQL statements)
- Using the SQLite engine directly, the performance of a large amount of data is good (only one SQL statement is required).
- Consumes less memory
- More Light weight
- Android and WP also support
Disadvantages of using SQLite directly
- Complex object relationships are maintained on their own
- No object change Tracking
- Not really object-oriented programming
- needs to be supplemented
Performance-related assessment
Overall, performance is not significantly different if you use SQLite as a DB store on the ground floor. Performance analysis This section is derived from this article, which analyzes the same number of data volumes, CoreData and direct use of sqlite comparison
http://www.drdobbs.com/mobile/ios-data-storage-core-data-vs-sqlite/240168843?pgno=2
Memory usage
Occupy Disk size
Query performance
How to choose
From the performance analysis above, as iOS device hardware performance is getting better, the difference between the two is not very large at all in terms of performance. views on StackOverflow or Google are also increasingly supporting the use of coredata instead of using SQLite directly. Below I will introduce, if I choose data storage, how to choose.
The first step, to be clear, is whether coredata or direct use of sqlite is for data persistence, the core of data persistence is what the data is stored.
The second step is to analyze your own data volume, the relationship between data, and the operation of the data. Give priority to CoreData, because you learn to really find it very useful, most of the app's data volume does not reach the CoreData performance bottleneck. But under the circumstances, consider SQLite
- Cross-platform. This is coredata not supported, it is part of the cocoa, meaning is implemented in C, if the data to be migrated to Android or PC, do not use CoreData
- A large batch of updates, deleting data. For example, there are 10,000 stores, each with a bool value to represent a state, and the efficiency of using coredata is very low.
- needs to be supplemented
What happens when CoreData encounters a performance bottleneck?
In this article, I briefly describe how to use log and performance evaluation tools to analyze
CoreData Performance-related
Most coredata performance problems are due to improper use. For example, a large number of data operations on the main thread. There are problems, priority to find solutions, whether it is StackOverflow or Google, almost all of the problems you meet others have encountered. In addition, if there is time, I highly recommend reading the official website of the document, Core Data Programming Guide
Finally, three libraries are recommended when using CoreData.
- Conversion of mantle objects to JSON
- Magicalrecord easy to create stacks
- RestKit, support network and map to CoreData
Other reference links
http://objccn.io/issue-4-3/
Http://stackoverflow.com/questions/523482/core-data-vs-sqlite-3
Http://stackoverflow.com/questions/1318467/use-coredata-or-sqlite-on-iphone
Copyright NOTICE: This article is for bloggers original article, if you need to reprint please indicate the source
IOS Persistent storage CoreData VS Direct SQLite