Thursday, May 2, 2013

NSKeyedArchiver finishEncoding example ios


Instructs the receiver to construct the final data stream.
- (void)finishEncoding
Discussion of [NSKeyedArchiver finishEncoding]
No more values can be encoded after this method is called. You must call this method when finished.
Example of [NSKeyedArchiver finishEncoding]
NSMutableData *data = [[NSMutableData alloc]init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];
[archiver encodeObject:YOURDICTIONARY forKey: YOURDATAKEY];
archiver finishEncoding];
[data writeToFile:YOURFILEPATH atomically:YES];
[data release];
[archiver release];
Example of [NSKeyedArchiver finishEncoding]
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

[archiver encodeObject:someObject forKey:@"people"];
[archiver encodeObject:anotherObject forKey:@"places"];
[archiver encodeObject:thirdObject forKey:@"things"];
[archiver finishEncoding];

[data writeToURL:someUrl atomically:YES];
[archiver release];