Last active
August 29, 2015 13:57
-
-
Save paulrehkugler/9360998 to your computer and use it in GitHub Desktop.
Proper string format tokens for NSInteger, NSUInteger, and CGFloat... Ewww
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
- (BRYDescriptionBuilder *)appendInteger:(NSInteger)integer withName:(NSString *)name { | |
#if defined(__LP64__) && __LP64__ | |
return [self appendString:[NSString stringWithFormat:@"%li", integer] withName:name]; | |
#else | |
return [self appendString:[NSString stringWithFormat:@"%i", integer] withName:name]; | |
#endif | |
} | |
- (BRYDescriptionBuilder *)appendUnsignedInteger:(NSUInteger)unsignedInteger withName:(NSString *)name { | |
#if defined(__LP64__) && __LP64__ | |
return [self appendString:[NSString stringWithFormat:@"%lu", unsignedInteger] withName:name]; | |
#else | |
return [self appendString:[NSString stringWithFormat:@"%u", unsignedInteger] withName:name]; | |
#endif | |
} | |
- (BRYDescriptionBuilder *)appendFloat:(CGFloat)floatValue withName:(NSString *)name { | |
// apparently %f works for float _and_ double | |
#if defined(__LP64__) && __LP64__ | |
return [self appendString:[NSString stringWithFormat:@"%f", floatValue] withName:name]; | |
#else | |
return [self appendString:[NSString stringWithFormat:@"%f", floatValue] withName:name]; | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment