String resources Xcode + swift

后端 未结 1 991
故里飘歌
故里飘歌 2021-01-04 01:25

I am new in iOS developing and in Swift language. And I try to make simple iOS application, and I need to have some string resources (for labels and text fields) in app. Of

1条回答
  •  执笔经年
    2021-01-04 02:00

    Your best bet is creating a file called Localizable.strings. In this file you can make localised string variables you can use throughout your application. Define strings like this;

    "hello_world" = "Hello World!";
    

    Use them in your Obj/C code like so;

    NSLocalizedString(@"hello_world", nil);
    

    Or in Swift;

    NSLocalizedString("hello_world", comment: "")
    

    p.s., I haven't tested this. Swift code might be faulty because of the fact I can't test this atm.

    0 讨论(0)
提交回复
热议问题