Friday, May 3, 2013

NSKeyedUnarchiver decodeFloatForKey example ios


decodeFloatForKey:

Decodes a single-precision floating-point value associated with a given key.
- (float)decodeFloatForKey:(NSString *)key
Parameters
key
A key in the archive within the current decoding scope. key must not be nil.
Return Value of [NSKeyedUnarchiver decodeFloatForKey]
The single-precision floating-point value associated with the key key. Returns 0.0 if keydoes not exist.
Discussion
If the archived value was encoded as double precision, the type is coerced, loosing precision. If the archived value is too large for single precision, the method raises anNSRangeException.
Example of [NSKeyedUnarchiver decodeFloatForKey]
- (id)initWithCoder:(NSCoder *)coder {
    [super init];
    self.name = [coder decodeObjectForKey:@"name"];
    self.expectedRaise = [coder decodeFloatForKey:@"expectedRaise"];
    return self;
}
Example of [NSKeyedUnarchiver decodeFloatForKey]
- (id)initWithCoder:(NSCoder *) coder {
    self = [[Currency alloc] init];
    if (self != nil)
    {
        code = [[coder decodeObjectForKey:keyCode] retain];
        description = [[coder decodeObjectForKey:keyDescription] retain];
        value = [coder decodeFloatForKey:keyValue];
    }   
    return self;
}