This problem has been clarified.
I have discussed this issue a lot abroad. For details, refer
Http://ablogontech.wordpress.com/2009/07/13/using-a-pre-populated-sqlite-database-with-core-data-on-iphone-os-3-0/
In addition, Apple's official explanation of this: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdFAQ.html how do I initialize
Store with default data? This section.
The above articles are summarized as follows:
1. Why are there strange names starting with Z and those strange tables and fields?
This is a private format that Apple supports coredata. When coredata is used and the-(nspersistentstorecoordinator *) persistentstorecoordinator method is called, IOS coredata automatically creates a. SQLite file.
This file will be automatically stored in your app document directory with readable and writable capabilities. Check the SQLite file to find the strange names and usage.
2. How to initialize the default data in the table? Look at the link: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdFAQ.html
How do I initialize a store with default data
The basic meaning is that if you use this format, you will basically have nothing to do with yourself. Unless you store your data in a resource file, such as XML, and then initialize it.
However, after testing, I found some methods that do not use Ios to initialize the default data,
The details are as follows:
1) copy the. SQLite file automatically generated in the simulator.
2) use sqlite3 or any tool to insert the data you want to insert.
3) Put the inserted sqls file into your project as a resource. then, call the following function before persistentstorecoordinator (this function is to put your file in the system so that IOS can use your file instead of generating other files by default) this is basically the case.
-(Void) copydatabasefileifneed
{
Nsfilemanager * filemanager = [nsfilemanager defaultmanager];
Nsurl * documentsdir = [self applicationdocumentsdirectory];
Nsurl * writabledbpath = [documentsdir urlbyappendingpathcomponent: @ "Default. SQLite"];
Bool dbexists = [filemanager fileexistsatpath: [writabledbpath path];
If (! Dbexists ){
// The writable dB doesn't exist so we'll copy our default one there.
Nsurl * defaultdbpath = [[nsbundle mainbundle] urlforresource: @ "xcloth" withextension: @ "SQLite"];
Nserror * error;
Bool success = [filemanager copyitematurl: defaultdbpath tourl: writabledbpath error: & error];
If (! Success ){
Nsassert1 (0, @ "failed to create writable database file with message
'% @'. ", [Error localizeddescription]);
}
Nslog (@ "% @", @ "DB is not exist ");
}
Else
{
Nslog (@ "% @", @ "DB is exist .");
}
}