Closed iluuu1994 closed 10 years ago
+1, love it.
:+1:
How about -withFormat
?
That'd give it a perfect hint, altho the choice is on you. Love the idea.
@supermarin Agreed.
Great! I'll create a pull-request soon.
I think it should be formatWithArgs
since it would work in this way [formatString formatWithArgs:arg1, arg2, ...]
If you wanted to shorten it, I'd be OK with withArgs
although it loses some clarity.
Hm, that makes sense; altho it could get verbose-y again. Here're the examples written down
[@"Hello %@" format:@"world"];
[@"Hello %@" withFormat:@"world"];
[@"Hello %@" withArgs:@"world"];
[@"Hello %@" formatWithArgs:@"world"];
[NSString stringWithFormat:@"Hello %@", @"world"];
NSStringWithFormat(@"Hello", @"world");
@iluuu1994 it's also worth pointing out that the main goal of NSStringWithFormat
wasn't shortening, it was more avoiding bracketception and improving readability.
Agreed. See this comparison:
[@"Hello %@" formatWithArgs:@"world"];
NSStringWithFormat(@"Hello %@", @"world");
I think the latter is much clearer to read.
@neilco Good point.
I like withArgs:
, although formatWithArgs:
would be clearer.
It's your repo, so I guess you guys decide.
@supermarin
that the main goal of NSStringWithFormat wasn't shortening, it was more avoiding bracketception
Well if that's the case my idea isn't worth a lot. Let me see if I find a more elegant solution. Until then, I'll close the issue.
fair enough, thanks @iluuu1994!
As you all know,
[NSString stringWithFormat:@"...", ...]
is a lot of syntax for something so common. This is why ObjectiveSugar implemented theNSStringWithFormat
function. It is indeed shorter, but well... not a lot.How about a
format:
method onNSString
?[@"..." format:...]
would be much more appealing in my opinion.I will implement this method and update the tests and doc if anyone finds this useful.