Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Shorter NSStringWithFormat #73

Closed
iluuu1994 opened this issue Mar 19, 2014 · 10 comments
Closed

Shorter NSStringWithFormat #73

iluuu1994 opened this issue Mar 19, 2014 · 10 comments

Comments

@iluuu1994
Copy link

As you all know, [NSString stringWithFormat:@"...", ...] is a lot of syntax for something so common. This is why ObjectiveSugar implemented the NSStringWithFormat function.
It is indeed shorter, but well... not a lot.

How about a format: method on NSString?
[@"..." 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.

@zenangst
Copy link

+1, love it.

@3lvis
Copy link

3lvis commented Mar 19, 2014

👍

@supermarin
Copy link
Owner

How about -withFormat?

That'd give it a perfect hint, altho the choice is on you. Love the idea.

@iluuu1994
Copy link
Author

@supermarin Agreed.

Great! I'll create a pull-request soon.

@neilco
Copy link
Collaborator

neilco commented Mar 19, 2014

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.

@supermarin
Copy link
Owner

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.

@neilco
Copy link
Collaborator

neilco commented Mar 19, 2014

Agreed. See this comparison:

[@"Hello %@" formatWithArgs:@"world"];
NSStringWithFormat(@"Hello %@", @"world");

I think the latter is much clearer to read.

@iluuu1994
Copy link
Author

@neilco Good point.

I like withArgs:, although formatWithArgs: would be clearer.
It's your repo, so I guess you guys decide.

@iluuu1994
Copy link
Author

@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.

@supermarin
Copy link
Owner

fair enough, thanks @iluuu1994!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants