What kind of string interpolation is this in Swift? {0} ...

So String interpolation is possible in Swift. However, the samples i have seen are either expressions or variables placed inside the "".

Is it possible to replace with values if you have {0} and {1} in the string? I do not know what this is called in Swift if this is possible.

I thought it is still interpolation but all I see are posts that do not have {0} ...

Or is this feature not available in Swift?

Yes, you can, using format. Here some examples:

let device = "iPhone"
String(format: "Turn your %@", device) // for a String
let lapse = 5
String(format: ("Do it in %d minutes.", lapse) // with Int
String(format: "Turn your %@ in %d minutes.", device, lapse) // both

This can also be localized:

String(format: NSLocalizedString("Do it in %d minutes.", comment: ""), lapse)

All formats here: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

What kind of string interpolation is this in Swift? {0} ...
 
 
Q