The data persistence provided by IOS is: Sqlitecoredata Property list, Nsuserdefault object archive.
Here's a brief introduction to object archiving in iOS development :
An object archive is an object archive that is saved as a file to disk (also known as serialization, persistence) when it is used to read the file's save path to read the contents of the files (also known as the pickup, deserialization)
Object archived files are confidential on the disk cannot view the contents of the file, and the attribute list is clear text can be viewed)
There are two ways to archive objects: 1. Archive objects in Foundat 2. Custom Object Archiving
1. Simple Object Archiving
Use of two classes: Nskeyeda Richivnskeyedunarchiver
Nsstr*homedirectori=nshomedirectori; Get root directory
Nsstringhomepath=[homedirectoristringbya ppendingpathcomponent:@ "Custom file name, such as Test.archiver"];
NSA rrai*[email protected][@ "abc", @ "123", @12];
Boolflag=[nskeyeda RichivarchiveRootObject:arraitoFile:homePath];
ifflag{
[Email protected] "Archive successful! ";
}
Read the contents of the archive file:
NSA Rrai*arrai=[nskeyedunarchivunarchiveobjectwithfile:homepath];
[Email protected] "%@", Arrai;
This makes it easy to implement archiving and reconciliation of the NSA Rrai object.
But this way of archiving has a drawback, is that a file can only save an object, if there are multiple objects to be saved, it is not a lot of n files, so it is not very suitable for the following this way of archiving.
2. Custom content Archiving
Archive:
Using NSData instances as archived storage data
Add archived content---Use key-value pairs
Complete archiving
Solution Archive:
Read files from disk, generate NSData instances
Based on NSData instances and initial solution archive instances
Archive, access value according to Kei
nsstr*homedirectori=nshomedirectori;//getting the root directory
Nsstringhomepath=[homedirectoristringbya ppendingpathcomponent:@ "Custom file name, such as Test.archiver"];
Nsmutabledata*data=[[nsmutabledataalloc]init];
Nskeyeda Rchiv*archiv=[[nskeyeda Rchivalloc]initforwritingwithmutabledata:data];
[archivencodefloat:50forkey:@ "Age"];
[archivencodeobject:@ "Jack" forkey:@ "name"];
[Archivfinishencoding]; End Add object to data
[Archivrelease];
[Datawritetofile:homepath atomically:yes];//writes data to a file to be saved on disk
Ndata*content=[nsdatadatawithconenteoffile:homepath];
Nskeyedunarchiv*unarchiv=[[nskeyedunarchivalloc]initforreadingwithdata:content];
floatag=[unarchivdecodefloatforkey:@ "Age"];
nsstr*name=[unarchivdecodeobjectforkey:@ "Name"];
In iOS development, in addition to archiving issues, it is often not aware of security issues. Don't think, Android will explode the loophole, as long as WireLurker appeared, the security myth of iOS no longer exists. and currently in the country, iOS security encryption protection This piece is still blank. However, the vast majority of iOS developers do not have to worry, because in the early days, there has been a platform to launch the iOS app encryption service, for the technical principles of iOS and the principle of decoding, respectively, from the local data, method body/method name, URL encoding, program structure, The network transmits data and so on several aspects to the iOS application to carry on the omni-directional protection, and can provide the custom solution according to the iOS application user's demand, thus realizes the iOS anti-cracking protection. iOS app encryption Http://www.ijiami.cn/ios
An elementary introduction to object archiving in iOS development