Skip to content

Instantly share code, notes, and snippets.

@alexrepty
Created September 26, 2014 12:50
Show Gist options
  • Save alexrepty/6595ab6331ada5ac332b to your computer and use it in GitHub Desktop.
Save alexrepty/6595ab6331ada5ac332b to your computer and use it in GitHub Desktop.
I learned about %1$@, %2$@ etc. today thanks to Wordcrafts
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
NSString *foo = @"foo";
NSString *bar = @"bar";
NSString *oldSkool = [NSString stringWithFormat:@"%@ %@", foo, bar];
NSString *original = [NSString stringWithFormat:@"%1$@ %2$@", foo, bar];
NSString *reversed = [NSString stringWithFormat:@"%2$@ %1$@", foo, bar];
NSLog(@"oldSkool: %@\noriginal: %@\nreversed: %@", oldSkool, original, reversed);
[p release];
}
// Output:
// 2014-09-26 14:48:56.731 PlaceholderOrder[38717:507] oldSkool: foo bar
// original: foo bar
// reversed: bar foo
// Source: https://www.wordcrafts.de/nice-to-know
@alexrepty
Copy link
Author

Here's the link in a clickable version: https://www.wordcrafts.de/nice-to-know

Be sure to check out the pitfalls section at the bottom of that page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment