2

What I want to know is how to create in swift a string with notation on localizable file and replace this notation just before.

"welcome" = "Hello %@, Welcome!"
"seeYou"  = "Goodbye %@"
"update"  = "All your profile data was update, %@"

in another file:

func showMessage(name : String){
  print(welcome,name)
}

thanks for the help,

Filipe

FilipeFaria
  • 639
  • 1
  • 10
  • 16

2 Answers2

7

It's much easier in Swift than in Objective-C by using String Interpolation

let name = "Filipe"
print("Hello \(name), Welcome!")

or the plus operator

print("Hello " + name + ", Welcome!")

In an environment to process localizable strings use

let welcome = "Hello %@, Welcome!"

func showMessage(name : String){
  print(String(format: NSLocalizedString(welcome, comment: ""), name))
}

showMessage("Filipe")
vadian
  • 274,689
  • 30
  • 353
  • 361
6

You can do this:

func showMessage(name : String) {
    let msg : String = String(format: "Hello %@, Welcome!", name)
    print(msg)
}

Check this link.

hugonardo
  • 337
  • 2
  • 9