Skip to content

Instantly share code, notes, and snippets.

@paulrehkugler
Last active August 29, 2015 13:57
Show Gist options
  • Save paulrehkugler/9360998 to your computer and use it in GitHub Desktop.
Save paulrehkugler/9360998 to your computer and use it in GitHub Desktop.
Proper string format tokens for NSInteger, NSUInteger, and CGFloat... Ewww
- (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