iOS Learning (OC language) Knowledge Point finishing
I. Archiving and unpacking operations
1) Archiving is a process that stores one or more objects so that they can be restored later, including storing the object in a file and then reading it later
Archive data objects into a plist file
2) plist files can only be stored in: NSString, NSDate, NSNumber, Bool, NSData, Nsarray, nsdictionary
and Nsarray and nsdictionary can only be the above types
3) What type of data is archived and what type of data is used to receive the data.
4) Archiving cannot directly manipulate data for custom object types.
5) Archive and archive Operation example code:
1 //Create a two-dimensional array (each element in the array is an array object)2Nsmutablearray *array1=[[Nsmutablearray alloc]init];3 for(intI=0;i<4; i++){4[Array1 addobject:[nsstring stringWithFormat:@"str%d", i+1]];5 }6 7Nsmutablearray *array2=[[Nsmutablearray alloc]init];8 for(intI=0;i<5; i++){9[Array2 addobject:[nsnumber numberwithint:arc4random ()% -]];Ten } One ANsarray *bigarray=@[array1,array2]; - //writes an array object to a file (written in memory, if the write is successful, immediately to the file) -[Bigarray WriteToFile:@"/users/kingkong/desktop/day08/array.plist"Atomically:yes]; the - //reads the contents of the plist file directly into the array -Nsarray *newarray=[[nsarray Alloc]initwithcontentsoffile:@"/users/kingkong/desktop/day08/array.plist"]; -NSLog (@"%@", NewArray); + -Nsarray *[email protected][@"[email protected]",@"[email protected]"]; + //Create a Dictionary object ANsdictionary *dict=[nsdictionary Dictionarywithobjectsandkeys:@"Zhangsan",@"name",@"123456",@"Password", emails,@"Email", nil]; at //writing a Dictionary object to a file -[Dict WriteToFile:@"/users/kingkong/desktop/day08/dict.plist"Atomically:yes]; - - //Store the plist file in a dictionary as read -Nsdictionary *newdict=[nsdictionary Dictionarywithcontentsoffile:@"/users/kingkong/desktop/day08/dict.plist"]; -NSLog (@"%@", newdict);
iOS Phase Learning 18th Day Notes (archive and archive operations)