Created by Jamz Tang at 27 August 2011
If you thinks that +[NSString stringWithFormat:] is simply annoying.
If you missed the C style string formatter like printf() or NSLog().
[NSString stringWithFormat:@”Why should I type this long?”];
Consider following helper:
//
// JTStringAddition.h
//
// Created by James Tang on 27/08/2011.
// http://ioscodesnippet.tumblr.com/
//
NSString *NSStringf(NSString *format, ...);
//
// JTStringAddition.m
//
// Created by James Tang on 27/08/2011.
// http://ioscodesnippet.tumblr.com/
//
#import "JTStringAddition.h"
NSString *NSStringf(NSString *format, ...) {
va_list ap;
NSString *str;
va_start(ap,format);
str=[[NSString alloc] initWithFormat:format arguments:ap];
va_end(ap);
return [str autorelease];
}
NSStringf(@”It’s just so much easier. %@”, @”Really.”);
Clone this repository:
git clone git://gist.github.com/1578509.git JTStringAddition
If you think this is useful, share this article with your friends :)
blog comments powered by DisqusUINibDecoderProxy Observes what's encoded in an NSCoder object
JTKeyValueObserver Revisiting KVO+Block, the simplest version.
MethodSwizzle Method Swizzling in Objective-C
UITableViewDeleteActionResponder Quick hack to enable delete menu item in UITableView menuController
UIApplicationAddition Quickly switch supported UIInterfaceOrientation for your View Controllers
JTTargetActionBlock Adding Block support for UIControl's Target-Action mechanism
NSArray-JTArraySplit Splitting an array to several components
UIImage+JTImageDecode Force decompressing UIImage in background to achieve better performance
UINavigationBar-JTDropShadow Adding drop shadow on UINavigationBar (before iOS 6)
UIImage-JTImageCrop Crop an image in specific rect
UIView+JTRemoveAnimated Adding fadeout effect to any -[UIViews removeFromSuperview]
JTStringAddition NSStringf. Simpler printf styled +[NSString stringWithFormat:]
UIView-JTViewToImage Rendering any UIViews into UIImage in one line (updated with iOS 7 support)
NSObject-JTNibLoader Loading a Nib file programmatically using NSObject category
UIImage-JTColor Creating a placeholder UIImage dynamically with color
NSObject-JTCancelableScheduledBlock Cancelable Scheduled Blocks in Objective-C