Friday, May 3, 2013

NSKeyedUnarchiver initForReadingWithData example ios


Initializes the receiver for decoding an archive previously encoded by NSKeyedArchiver.
- (id)initForReadingWithData:(NSData *)data
An archive previously encoded by NSKeyedArchiver.
Return Value of [NSKeyedUnarchiver initForReadingWithData]
An NSKeyedUnarchiver object initialized for for decoding data.
When you finish decoding data, you should invoke finishDecoding.
This method raises an NSInvalidArchiveOperationException if data is not a valid archive.
Example of [NSKeyedUnarchiver initForReadingWithData]
NSData *data = [[NSMutableData alloc]initWithContentsOfFile:YOURFILEPATH];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
YOURDICTIONARY = [unarchiver decodeObjectForKey: YOURDATAKEY];
[unarchiver finishDecoding];
[unarchiver release];
[data release];
Example of [NSKeyedUnarchiver initForReadingWithData]
- (void)readVenueArchiveFile:(NSString *)inFile key:(NSString *)inKey
    NSMutableData *theData;
    NSKeyedUnarchiver *decoder;

    theData = [[NSData alloc] initWithContentsOfFile:inFile];
    decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
    ListClassName *decodedList = [decoder decodeObjectForKey:inKey];
    self.venueIOList = decodedList;
    [decoder finishDecoding];
    [decoder release];
    [theData release];