Created
April 8, 2014 23:23
-
-
Save qwzybug/10207992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSMutableDictionary (ValueHolding) | |
- (void)setDouble:(double)number forKey:(NSString *)key; | |
- (double)doubleForKey:(NSString *)key; | |
- (void)setCGFloat:(CGFloat)number forKey:(NSString *)key; | |
- (CGFloat)CGFloatForKey:(NSString *)key; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSDictionary+ValueHolding.h" | |
@implementation NSMutableDictionary (ValueHolding) | |
- (void)setDouble:(double)number forKey:(NSString *)key; | |
{ | |
[self setValue:[NSNumber numberWithDouble:number] forKey:key]; | |
} | |
- (double)doubleForKey:(NSString *)key; | |
{ | |
return [[self objectForKey:key] doubleValue]; | |
} | |
- (void)setCGFloat:(CGFloat)number forKey:(NSString *)key; | |
{ | |
[self setValue:[NSNumber numberWithDouble:number] forKey:key]; | |
} | |
- (CGFloat)CGFloatForKey:(NSString *)key; | |
{ | |
return [[self objectForKey:key] doubleValue]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableDictionary *valueHolder = [NSMutableDictionary dictionary]; | |
double number = 123.45678; | |
[valueHolder setDouble:number forKey:@"doubleVal"]; | |
[valueHolder setCGFloat:number forKey:@"floatVal"]; | |
NSLog(@"Value holder: %@", valueHolder); | |
number = [valueHolder doubleForKey:@"doubleVal"]; | |
[valueHolder setDouble:number forKey:@"doubleVal"]; | |
[valueHolder setCGFloat:number forKey:@"floatVal"]; | |
NSLog(@"Value holder: %@", valueHolder); | |
[valueHolder setCGFloat:[valueHolder doubleForKey:@"doubleVal"] forKey:@"floatVal"]; | |
[valueHolder setDouble:[valueHolder doubleForKey:@"doubleVal"] forKey:@"doubleVal"]; | |
NSLog(@"Value holder: %@", valueHolder); | |
[valueHolder setCGFloat:[valueHolder CGFloatForKey:@"floatVal"] forKey:@"floatVal"]; | |
[valueHolder setDouble:[valueHolder CGFloatForKey:@"floatVal"] forKey:@"doubleVal"]; | |
NSLog(@"Value holder: %@", valueHolder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2014-04-08 16:21:23.078 TypeTest[8699:60b] Value holder: { | |
doubleVal = "123.45678"; | |
floatVal = "123.45678"; | |
} | |
2014-04-08 16:21:23.080 TypeTest[8699:60b] Value holder: { | |
doubleVal = "123.45678"; | |
floatVal = "123.45678"; | |
} | |
2014-04-08 16:21:23.081 TypeTest[8699:60b] Value holder: { | |
doubleVal = "123.45678"; | |
floatVal = "123.45678"; | |
} | |
2014-04-08 16:21:23.082 TypeTest[8699:60b] Value holder: { | |
doubleVal = "123.45678"; | |
floatVal = "123.45678"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment