How to create persistent storage on iPhone?
I would like to know which type of persistent storage would be safe to use for Archive files in iPhone? My archive files needs to be updated for every 30mins to 1hr, and i need to persist nearly 500开发者_运维知识库 to 600 archive files.
How to persist so many archive files on device? which persistent storage mehanism woulb be better to use?
Thank You.
If you really want to choose a DB solution, then I would recommend sticking with what Apple recommends - CoreData. There is a learning curve, but there are some great docs on the developer portal which should get you up to speed quickly. CoreData abstracts the DB allowing you to save and retrieve objects rather than write a bunch of SQL.
You might instead wish to look at reading/writing files to the Application home directory. For more info, please look at the "iOS Application Programming Guide"which has a section on "Files and the File System". You could then persist your 500 files directly to flash, as opposed to using a DB/CoreData solution.
Files and the File System
Every application has a protected area in which it can create and modify files. In addition, the system allows applications to share files with each other (and with the user) through well-defined and secure means. However, supporting those means requires work on your part. The following sections describe the types of file-related operations you can perform in your applications.
Link to the programming guide:
http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StandardBehaviors/StandardBehaviors.html
NSUserDefaults is a quick and easy way to store small amounts of data for you app. We use NSUserDefaults for persistant storage in iphone, like Shared Preference in Android.
Storing Data:
// create a standardUserDefaults variable
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
// saving an NSString
[standardUserDefaults setObject:@"mystring" forKey:@"string"];
// synchronize the settings
[standardUserDefaults synchronize];
Receiving Data:
// create a standardUserDefaults variable
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
// getting an NSString object
NSString *myString = [standardUserDefaults stringForKey:@"keyToLookupString"];
精彩评论