Friday, May 3, 2013

NSKeyedUnarchiver decodeDoubleForKey example ios


Decodes a double-precision floating-point value associated with a given key.
- (double)decodeDoubleForKey:(NSString *)key
A key in the archive within the current decoding scope. key must not be nil.
Return Value of [NSKeyedUnarchiver decodeDoubleForKey]
The double-precision floating-point value associated with the key key. Returns 0.0 if keydoes not exist.
If the archived value was encoded as single-precision, the type is coerced.
Example of [NSKeyedUnarchiver decodeDoubleForKey]
-(id)initWithCoder:(NSCoder *)decoder
    // Init first.
    if(self = [self init]){

    ID = [decoder decodeIntForKey:@"ID"];
    GeoLat = [decoder decodeDoubleForKey:@"GeoLat"];
    GeoLong = [decoder decodeDoubleForKey:@"GeoLong"];
    self.Name = [decoder decodeObjectForKey:@"Name"];

    self.Address = [decoder decodeObjectForKey:@"Address"];
    self.Phone = [decoder decodeObjectForKey:@"Phone"];

    return self;
Example of [NSKeyedUnarchiver decodeDoubleForKey]
NSString *filePath = [self dataFilePath];
 if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
  NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]];
  NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];

  field1.text = [unarchiver decodeObjectForKey:kDataKey1];
  // snip another bunch of fields
  field37.text = [unarchiver decodeObjectForKey:kDataKey37];

  soundOn = [unarchiver decodeBoolForKey:kDataKey38];
  soundVolumeSlider.value = [unarchiver decodeDoubleForKey:kDataKey39];
  soundVolumeValue = [unarchiver decodeDoubleForKey:kDataKey39];
  tempArray = [unarchiver decodeObjectForKey:kDataKey46];

  [unarchiver finishDecoding];