Created
September 26, 2014 12:50
-
-
Save alexrepty/6595ab6331ada5ac332b to your computer and use it in GitHub Desktop.
I learned about %1$@, %2$@ etc. today thanks to Wordcrafts
This file contains hidden or 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
#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 |
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
Oh cool, that's awesome.