Reputation: 31
I am encoding a string with interpolation:
let name = "John" "My name is \(name)"
to a file
And i need to decode that string from file when running my code, i am expecting the string to print My name is John
, but all i get is My name is \(name)
Is there a way to let Swift understand string interpolation in this case?
Upvotes: 0
Views: 315
Reputation: 51983
A better solution could be to use String(format:)
and use any variable you want when parsing
Write "My name is %s" to file and then when reading it
let inString = "My name is %s" //from file really
let str = String(format: inString, "John")
Upvotes: 1