IOS: equivalent of strings.xml in app for iOS apps?

In the application I am making, I have many huge lines. I don’t want to hard code them into my code, because it makes the code unbearably dirty. When I made a similar application for Android, it was simple to declare a line in the strings.xml file as

<string name="hello_world">Hello World!!</string>

and access it in java file using

getString(R.string.hello_world);

How can I do something similar with iOS?

+4
source share
1 answer

You can put them in a file .plistand load them using the following code (which assumes a file with a name strings.plistthat was copied into the application bundle):

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"strings" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:filePath];
NSString *string1 = [dict objectForKey:@"string1"];

, , Apple Internationalization Localization - .

EDIT: / ; !

+4

Source: https://habr.com/ru/post/1544713/


All Articles