Created
December 5, 2012 22:14
-
-
Save supermarin/4219990 to your computer and use it in GitHub Desktop.
NSString literals
This file contains 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
// Currently, there's too much effort for printing strings with arguments. | |
// The current way | |
NSString *sentence = [NSString stringWithFormat:@"This is a text with argument %@", argument]; | |
// Possible literal | |
NSString *sentence = @("This is a text with argument %@", argument); | |
@neilco correct, but I'm not sure the compiler would be able to do it and maintain compatibility with C.
Wouldn't the compiler be more comfortable with:
NSString *sentence = @(@"This is a text with argument %@", argument);
Have you tried to ask Apple for this new feature? :)
@umairsd correct, that's the original proposal :)
@dilejmon, I haven't; wanted to see what others are saying. I don't know either what's the best place to ask this question :)
In the meantime, @neilco has built a macro _(@"text: %@", argument)
, but I find it a bit confusing for newcomers.
We ended up with NSStringWithFormat(@"text: %@", argument)
, you can find it in ObjectiveSugar
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the way Ruby does it. The ObjC equivalent would be: