Atomically:yes];
Access: Gets the data from the path construct Nskeyedunarchiver instance, using the Decodexxxforkey method to get the object in the file.
Nsmutabledata *datar = [[Nsmutabledata Alloc]initwithcontentsoffile:multihomepath];
Nskeyedunarchiver *unarchiver = [[Nskeyedunarchiver alloc]initforreadingwithdata:dater];
Cgpoint pointr = [unarchiver decodecgpointforkey:@"Kpoint"];
you can use the Decodeobject:forkey method to decode the instance variable3.2 How to use1> Custom entity Classes @interface cycontact:nsobject /** name * /@property (nonatomic,copy) nsstring *name; /** Telephone * /@property (nonatomic,copy) nsstring *phone; @end2> implementation of Nscoding protocol method #pragma mark-nscoding protocol method/* Encodes the receiverusing a given archiver via a given AR The chiver encodes the message receiver. The class terminal Encodewithcoder
(@ "%@", issuccess @ "person writes successfully": @ "person writes failed");Two. Anti-archivingThe reading of a complex object is called an anti-archiveNskeyedunarchiver Anti-archiving tool1. Get the data in the file, a. File path B. Find a data object to receive read resultsNSData *undata = [NSData Datawithcontentsoffile:personpath];2. Creating an anti-archiving toolNskeyedunarchiver *unarchiver = [[Nskeyedunarchiver alloc]initforreadingwithdata:un
If you think of your Mac as your main work machine, and your coworkers use Windows, sometimes exchanging documents can be a pain, like the one you're talking about today: when a colleague passes you a zip file, and you extract it, you find some file names in Chinese, What you see is going to be a bunch of garbled characters ... Jay has been ignoring this problem until one day finally, to Google A, finally found the answer, here to share.In fact, the solution is very simple, the next software ins
Archiving and recovery archivingArchive, English archiver[' ɑrk?v?], this refers to storing OC objects as a file or a block of data on the network.Recovery archive, English unarchiver, refers to restoring an archived block of data from a file or network to an OC object in memory.Archiving and recovery is primarily used to store custom type objects, save custom data before a program is paused or closed, and read stored custom data after the program res
:@"num"]; [Archiver encodeobject:@"LJF"forkey:@"Name"];//Complete the encoding to populate the above archived data into data, where the archived objects are already stored[Archiver finishencoding];NSString*filepath = [Nshomedirectory () stringbyappendingpathcomponent:@"Array. LJF "];BOOLSuccess = [Data Writetofile:filepath atomically:YES];if(success) {NSLog(@"Archive Success"); }}//Solution 2-(void) nskeyedunarchivertwo{NSString*filepath = [Nshomedirectory () stringbyappendingpathcomponent:@"Arr
called) [archiver finishEncoding]; // write the archived data to the file [data writeToFile: path atomically: YES];
NSData
-
Restore from the same file
2
Items
Person
Object
Restore (Decoding) // read data from the file NSData * data = [NSData dataWithContentsOfFile: path]; // based on data, resolved to an authorization object NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data]; Person * person1 = [
operated.This section is not described in the book. It is estimated that the primary part is skipped.Tmp: The application temporarily stores files. When this is not required, the application deletes the file data under it.This file also provides the directory retrieval method:
JavaCode
14 .}
16. # pragma NSCopying protocol implementation
17.-(id) copyWithZone :( NSZone *) zone
18 .{
23 .}
24. @ end
Then, read and write the object archive.[Cpp] view plaincopy// Read the archive fileNSData * data
forkey:@ "Person1"];
[Archiver encodeobject:person2 forkey:@ "Person2"];
Archive complete (make sure to call this method)
[Archiver finishencoding];
Writes archived data to the file
[data Writetofile:path Atomically:yes];
Recovery (decoding):
Reading data from a file
nsdata *data = [NSData Datawithcontentsoffile:path];
According to the data, parse into a Nskeyedunarchiver object
nskeyedunarchiver *unarchiver = [[Nskeyedunarchiver alloc]
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.