iOS Phase Learning 18th Day Notes (archive and archive operations)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.