1

I know some ways to build strings in objective-c, but I'm curious if I can achieve following.

Currently I'm using this:

return [NSString stringWithFormat:sentence, str, units, remainingStr, unitsRemaining];

Where sentence is a NSString that looks like this:

@"You've completed %@ %@. You have %@ %@ to go."

My question is can I somehow directly tell to the parameters: str, units, remainingStr, unitsRemaining which placeholder to take, or my only option is the direct order?

For example I want str go take third placeholder from the left, and remainingStr take the first one.

Any kind of help is highly appreciated!

Eugene Gordin
  • 4,047
  • 3
  • 47
  • 80
  • 1
    It is possible to define the order but note that you always have to specify the type (e.g. `%.2f`, too). – Sulthan Nov 01 '14 at 22:35
  • 1
    See: [String Format Specifiers](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW1) – zaph Nov 02 '14 at 01:36

0 Answers0