Introduction Core data is a framework that appears after IOS5, which provides an object-relational mapping (ORM) function that enables the conversion of OC objects into data, stored in SQLite database files, and restores data saved in the database to OC objects. During this data operation, we do not need to write any SQL statements, which is somewhat similar to the famous Hibernate persistence framework, but the feature is definitely not hibernate powerful. Two, Core data usage Object Description: 1, Managed object Modelmanaged object model is the data modeling that describes the application, which contains the entities (entity), (property), read request (fetch requests), and so on. (English terminology is used below.) 2,managed Object Contextmanaged Object Context participates in the entire process of manipulating data objects and monitors changes in data objects to provide support for Undo/redo and to update the UI that binds to the data. The 3,persistent store coordinatorpersistent store coordinator is equivalent to a data File manager that handles the underlying read and write of data files. Generally we don't have to deal with it. 4,managed objectmanaged Object Data Objects, associated with the Managed object Context. In the 5,controller diagram, the green Array Controller, object controller, and Tree controllers are generally Control+drag to Managed object Co ntext bind to them so that we can manipulate the data visually in the nib. Specific usage: 1, the application first creates or reads a model file (suffix Xcdatamodeld) to generate Nsmanagedobjectmodel objects. The document application is generally read by nsdocument or its subclasses nspersistentdocument) from the model file (suffix Xcdatamodeld). 2, and then generate the Nsmanagedobjectcontext and Nspersistentstorecoordinator objects, the formerThe user transparently calls the latter to read and write to the data file. 3,nspersistentstorecoordinator is responsible for reading data from data files (XML, SQLite, binary files, etc.) to generate Managed object, or to save Managed object to write to the data file. 4,nsmanagedobjectcontext participates in the entire process of doing various operations on the data, which holds Managed Object. We use it to monitor Managed Object. The monitoring data object has two functions: support Undo/redo and data binding. This class is most commonly used. 5,array Controller, Object Controller, Tree controllers these controls are typically associated with nsmanagedobjectcontext, so we can manipulate the data objects visually in the nib through them. Third, Core data thread safety CoreData in Nsmanagedobjectcontext is not secure in multiple threads, and if you want multi-threaded access to CoreData, The best way to do this is to nsmanagedobjectcontext a thread, and each Nsmanagedobjectcontext object instance can use the same Nspersistentstorecoordinator instance. This instance can access persistent storage in a secure sequence, because Nsmanagedobjectcontext will be locked before nspersistentstorecoordinator. create a separate managed object context for each thread and share a single persistent store coordinator. This is the typically-recommended approach.
Core data for iOS and its thread safety