Format Specifiers

Format specifiers are placeholders in your strings that get replaced with values at runtime. Getting them wrong can crash your app.

Common Specifiers#

SpecifierTypeExample
%@Object/String"Hello, %@" → "Hello, John"
%lldInteger (64-bit)"%lld items" → "5 items"
%dInteger (32-bit)"%d items" → "5 items"
%fFloat/Double"%.2f miles" → "3.14 miles"
%%Literal %"100%% complete" → "100% complete"

How They Appear#

When you write Swift code with interpolation:

Text("Hello, \(name)!")
Text("\(count) items remaining")

Xcode extracts these as:

{
  "Hello, %@!": { ... },
  "%lld items remaining": { ... }
}

Positional Arguments#

For strings with multiple placeholders, use positional arguments so translators can reorder them:

English: "%1$@ sent %2$@ a message"
German:  "%2$@ erhielt eine Nachricht von %1$@"

The format is %[position]$[specifier]:

PositionalMeaning
%1$@First string argument
%2$@Second string argument
%1$lldFirst integer argument

AI Translation#

When using AI translation, XCStrings Translator:

  1. Instructs the AI to preserve all format specifiers
  2. Validates the output before saving
  3. Warns you if specifiers don't match

AI models generally handle format specifiers well, but always review warnings before accepting translations.

See Handling Format Specifiers for an interactive demo and best practices.