Coredata-Problems with permanent data storage

Source: Internet
Author: User

When using coredata, you must permanently Save the data and use NSManagedObjectContext.
Sava: method.

In this process, I found that all kinds of data cannot be saved, so it took me two days to solve it and search for various methods. However, there are countless methods that cannot solve my problems, at last, I found my problem, but it made me laugh and cry.

Summarize the solutions to problems encountered during storage:

1. Multiple Threads are used to operate the same NSManagedObjectContext object.

It is best to use one

NSManagedObjectContext object


2. NSManagedStoreCoordinator has cached data and needs to be refilled

[ManagedObjectContext setStalenessInterval: 0.0]; // forcibly loaded from disk


3. NSManagedObjectContext
Core data that fails to merge policies cannot be merged.

[ManagedObjectContext setMergePolicy: NSMergeByPropertyObjectTrumpMergePolicy]; // sets context object Merging

4. Database Path Problems

Check whether the database path is correct


5. The database structure is updated.

You need to delete the project from the simulator or on the real machine and recompile it with clean.


6. mismatch between the storage type and the type defined in the database


Finally, let's talk about my problem: Using coredata to create a table in the project, it will generate the database by itself, and each table has its own Z_PK, Z_ENT, z_OPT,

The primary key of the Z_PK table, which increases progressively from 1 and is unique.

The index value of the z_ent table in xcdatamodel. If there are 6 tables, the value range is [].

Z_opt indicates the number of operations performed on each data entry. The initial value is 1. If it is added, deleted, modified, and queried, 1 is added.

In order to test my program, I found the database and filled in the data, so that the values z_ent and z_opt were not filled, resulting in various failures when I saved the data,

The data inserted with the code will be automatically assigned values for the two fields, which has left me depressed for a long time. This is a long memory, even if the test data is not identified, it is better to generate it using code, not only to detect the code, but also to avoid this error ..


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.