The system type mainly refers to the NSString Nsdictionary,nsarray,nsdata,nsnumber type data (including the corresponding variable type);
These types have implemented the Nscoding protocol, supporting archiving,
Write Method:
Writetofile:atomically:
Read method:
-dictionarywithcontentsoffile:
-arraywithcontentsoffile:
-datawithcontentsoffile:
-stringwithcontentsoffile:
String Object Archive and archive atomically buffer pool
NSString *[email protected] "Hello oc!";
Write
BOOL falg=[str writetofile:@ "Str.txt" Atomically:yes encoding:nsutf8stringencoding Error:nil];
if (FALG) {
NSLog (@ "Str saved successfully!) ");
}
Read
NSString *readstr=[nsstring stringwithcontentsoffile:@ "Str.txt" encoding:nsutf8stringencoding Error:nil];
Array object archiving and solution archiving
Write
Nsarray *[email protected][@ "One", @ "one", @ "three"];
BOOL flag=[arr writetofile:@ "Arr.plist" atomically:yes];
if (flag) {
NSLog (@ "YES");
}
Read out
Nsarray *readarr =[nsarray arraywithcontentsoffile:@ "Arr.plist"];
Dictionary object archiving and solution archiving
Nsdictionary *[email protected]{@ "1": @ "one",
@ "2": @ "a",
@ "3": @ "three"};
Write
BOOL flag = [dic writetofile:@ "Dic.plist" atomically:yes];
if (flag) {
NSLog (@ "YES");
}
Nsdictionary *readdic = [nsdictionary dictionarywithcontentsoffile:@ "Dic.plist"];
NSLog (@ "readdic =%@", readdic);
object-c-System type Object archive