字符串资源Xcode + Swift [英] String resources Xcode + swift
问题描述
我是iOS开发和Swift语言的新手. 而且,我尝试制作简单的iOS应用程序,并且我需要在应用程序中包含一些字符串资源(用于标签和文本字段).当然,我可以将此字符串作为常量放入* .swift文件中,但是我认为这是一种不好的方法.我该怎么做?我需要一些东西作为Android中的字符串资源.我迅速使用Xcode 6 beta.
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 course, I can put this strings to my *.swift files as constants, but I think, it is a bad way. How can I do it? I need something as string resources in Android. I use Xcode 6 beta with swift.
TY为答案;)
推荐答案
您最好的选择是创建一个名为Localizable.strings
的文件.在此文件中,您可以创建可在整个应用程序中使用的本地化字符串变量.
定义这样的字符串;
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!";
像这样在您的Obj/C代码中使用它们;
Use them in your Obj/C code like so;
NSLocalizedString(@"hello_world", nil);
或者在Swift中;
Or in Swift;
NSLocalizedString("hello_world", comment: "")
p.s.,我尚未对此进行测试. Swift代码可能有问题,因为我无法测试此atm.
这篇关于字符串资源Xcode + Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!