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 ..