Common ways for iOS app data storage
1.lXML attribute list (plist) archive 2.lPreference (preferences) 3.lNSKeyedArchiver Archive (nscoding) 4.lsqlite35.lcore Data Documents: Saves data that needs to be persisted when the app runs, and it backs up the directory when itunes synchronizes the device. For example, a game app can save a game archive in this directory, TMP: Save the temporary data needed to run the app, and then delete the corresponding file from that directory when it's finished. When the app is not running, the system may also purge files in that directory. itunes syncs the device without backing up the directory Library/caches: saves data that needs to be persisted when the app runs, and itunes syncs the device without backing up the directory. Non-critical data with large storage volumes and no backup required Library/preference: Save all preferences for your app, and the iOS settings (settings) app will find the app's settings information in that directory. itunes synchronizes the device when it is backed up common ways to get a sandbox catalog by using the Nssearchpathfordirectoriesindomains function
Nsarray *array = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, NO); Nsuserdomainmask represents from the user folder, YES represents the wavy character "~" in the expanded path
NSString *documents = [array objectatindex:0]; In iOS, only one directory matches the parameters passed in, so there is only one element in the collection
Preferences: Cannot store custom objects, generally store user's account password information
1. Deposit Data
Nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults];
[Defaults setobject:@ "Itcast" forkey:@ "username"];
[Defaults setfloat:18.0f forkey:@ "Text_size"];
[Defaults setbool:yes forkey:@ "Auto_login"];
2. Reading data
Nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults];
NSString *username = [Defaults stringforkey:@ "username"];
float textSize = [Defaults floatforkey:@ "Text_size"];
BOOL autologin = [Defaults boolforkey:@ "Auto_login"];
[Defaults synchornize]; In order for the program to write immediately to call this method
Nskeyedarchiver: Need to comply with <NSCoding> agreement
Implement the following two methods
1. Encodewithcoder: This method is called every time the object is archived. In this method, you typically specify how to archive each instance variable in an object, and you can use the Encodeobject:forkey: method to archive instance variable 2. Initwithcoder: This method is called every time the object is recovered (decoded) from the file. In this method, you typically specify how to decode the data in a file as an instance variable of an object, and you can use the Decodeobject:forkey method to decode the instance variable
1. Deposit Data
[Nskeyedarchiver Archiverootobject:array Tofile:path];
2. Reading data
[Nskeyedunarchiver Unarchiveobjectwithfile:path];