Store NSMutable Array into sqlite database
hi i am writng an iphone app and need a bit of help.. i have this uitableview which displays data that is contained in a nsmutable array.. this data is retrieved via some operations therefore amount of data is not the same every time...
what i want to know is if i had something like:
NSMutableArray *mArray;
how would i go about storing and loading the 'mArray' from an sqlite database..
Further info as requested:
@Caleb
@westsider
Array Contents: The contents of the array are simple module names (i.e subjects that a student learns on a course), that are retrieved from a .ics calendar file with some parsing operations.. i end up with an array that contains the data i want and then i display it using a tableview..
Basically i need to initially save the module names that are stored in the array so that the next time the user opens the application, the module names are still there..
Why Core Data When the user selects a cell in tableview (i.e. selects a module) i want to push a开发者_开发问答nother view controller that displays the module name where the user can add other data/strings that should be saved..
What are the objects in the array? Are they all the same type? If they're dictionaries, do they all have the same keys? Are they made up of standard property list objects (NSDictionary, NSData, NSArray, NSString, NSNumber)? Why do you want to use an SQLite database rather than saving them some other way?
If you have an array of custom objects, the simplest thing to do is to implement NSCoding in the class (or classes) used in the array. Then, create an NSKeyedArchiver and archive your array using -archiveRootObject:toFile:.
As long as everything in your array conforms to NSCoding
you can serialize your array.
Look at Archives and Serialization Programming Guide for creating and decoding archives.
You will need a column in your sqlite table that is of data type blob and use sqlite3_bind_blob to store it.
This link shows how to create an archive from an object. http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Archiving/Articles/creating.html#//apple_ref/doc/uid/20000949-BABGBHCA
This post shows how to retrieve a blob from a sqlite database. retrive-nsdata-from-sqlite-stored-in-blob-data-type-for-iphone-app
精彩评论