My goal is to create a sqlite database and populate it with data (maybe 1000+ rows) and use this database to preload the main data and populate the table view.
For now, I have a table view that works with Core Data, Managed Object Models. I can add elements and delete elements - basically I have a Master-Detail template, but with my own model.
Question:
How to create sqlite database in the correct format for use with Core Data?
I have successfully done this using the provided SQL databases and tutorials from books. I noticed that the runaway table (for example) in my tutorial is written "ZFUGITIVE" in the provided sqlite database. All its columns have "Z" attached to the front ("ZFUGITIVEID", "ZNAME" ...) and three additional columns ("Z_PK", "Z_ENT", "Z_OPT") exist that are not included in the managed object model ( .xcdatamodeld). Besides the “Z” of all sample names and additional columns, I also see (in this .sqlite db that comes with the tutorial) that there are two additional tables, “Z_PRIMARYKEY” and “Z_METADATA”.
I am familiar with sqlite terminal commands and can create a database, but it does not have the correct formatting, extra rows, or extra metadata tables. What I did as an experiment is to take the sqlite database table of the above Fugitive and add another table to it. At first, I called it the “thing” table with the columns “thingID” and “title”. I created a managed object for it and linked it to my table view. I could not get data for preload in my main data / my table view for life. I did not receive error messages, it just did not load data (this allowed me to add and remove new elements, like the Master-Detail template).
, "" "ZTHING" ( "Z_PK", "Z_ENT", "Z_OPT", "ZTHINGID" "ZTITLE" ), . , , , , . , .
, , , Z_METADATA ( Z_UUID), : [ ]
Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x5b489c0 {metadata=<CFBasicHash 0x5b4e960 [0x2651380]>{type = immutable dict, count = 7,
entries =>
2 : <CFString 0x5b4ea40 [0x2651380]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x5b4eb10 [0x2651380]>{type = immutable, count = 0, values = ()}
4 : <CFString 0x5b4ea90 [0x2651380]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x5b4e530 [0x2651380]>{value = +248, type = kCFNumberSInt64Type}
6 : <CFString 0x5b4eac0 [0x2651380]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x5b4eba0 [0x2651380]>{type = immutable dict, count = 1,
entries =>
1 : <CFString 0x5b4eb30 [0x2651380]>{contents = "Fugitive"} = <CFData 0x5b4eb50 [0x2651380]>{length = 32, capacity = 32, bytes = 0xe33370b6e7ca3101f91d25951e8bfe01 ... 9e50237bb313d390}
}
7 : <CFString 0x1ee464 [0x2651380]>{contents = "NSStoreUUID"} = <CFString 0x5b4e850 [0x2651380]>{contents = "E711F65F-3C5A-4889-872B-6541E4B2863A"}
8 : <CFString 0x1ee324 [0x2651380]>{contents = "NSStoreType"} = <CFString 0x1ee2e4 [0x2651380]>{contents = "SQLite"}
9 : <CFString 0x5b4ea10 [0x2651380]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0x5d0b520 [0x2651380]>{value = +3, type = kCFNumberSInt32Type}
10 : <CFString 0x5b4eaf0 [0x2651380]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x5b4ebf0 [0x2651380]>{contents = "2"}
}
, reason=The model used to open the store is incompatible with the one used to create the store}, {
metadata = {
NSPersistenceFrameworkVersion = 248;
NSStoreModelVersionHashes = {
Fugitive = <e33370b6 e7ca3101 f91d2595 1e8bfe01 3e7fb4de 6ef2a31d 9e50237b b313d390>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
);
NSStoreType = SQLite;
NSStoreUUID = "E711F65F-3C5A-4889-872B-6541E4B2863A";
"_NSAutoVacuumLevel" = 2;
};
reason = "The model used to open the store is incompatible with the one used to create the store";
}
, .