Friday, May 3, 2013

NSKeyedUnarchiver decodeObjectForKey example ios


decodeObjectForKey:

Decodes and returns an object associated with a given key.
- (id)decodeObjectForKey:(NSString *)key
Parameters of [NSKeyedUnarchiver decodeObjectForKey]
key
A key in the archive within the current decoding scope. key must not be nil.
Return Value
The object associated with the key key. Returns nil if key does not exist, or if the value forkey is nil.
Example of [NSKeyedUnarchiver decodeObjectForKey]
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 decodeObjectForKey]
- (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];
}