Created by Jamz Tang at 27 August 2011

NSStringf. Simpler printf styled +[NSString stringWithFormat:]

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.

NSString *NSStringf(NSString *format, ...);
//  JTStringAddition.m
//  Created by James Tang on 27/08/2011.

#import "JTStringAddition.h"

NSString *NSStringf(NSString *format, ...) {
    va_list ap;
    NSString *str;
    str=[[NSString alloc] initWithFormat:format arguments:ap];

    return [str autorelease];

NSStringf(@”It’s just so much easier. %@”, @”Really.”);


Clone this repository:
git clone git:// JTStringAddition

| More...

If you think this is useful, share this article with your friends :)

blog comments powered by Disqus