我应该如何存储一个大字符串,例如用户协议? [英] How should I store a large string, like a user agreement?

查看:140
本文介绍了我应该如何存储一个大字符串,例如用户协议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用像@"content"这样的字符串文字,但是我认为这浪费了内存.有针对这种情况的自定义解决方案吗?

I can use a string literal like @"content", but I think it’s a waste of memory. Is there a custom solution for this situation?

我是一个新的Xcoder,所以可能这不是一个好问题,但是我对NSString ...

I'm a new Xcoder, so may be this is not a good question, but I'm very confuse about the use of NSString...

推荐答案

将文本放入文件中.假设您将文件命名为userAgreement.txt.确保文件是目标的一部分(在主编辑器中打开文件时,请检查文件检查器"的目标成员身份"部分).

Put the text in a file. Let's say you name the file userAgreement.txt. Make sure the file is part of your target (check the Target Membership section of the File Inspector while you have the file open in the primary editor).

像这样在运行时读取文件内容:

Read the contents of the file at runtime like this:

NSString *path = [[NSBundle mainBundle] pathForResource:@"userAgreement" ofType:@"txt"];
NSString *userAgreement = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];

此方法的一个特点是您可以本地化文件,并且此代码将自动为用户的语言环境选择合适的版本.

A feature of this approach is that you can localize the file, and this code will automatically pick up the appropriate version for the user's locale.

请注意,如果您要使用自定义最终用户许可协议(EULA),并且希望将此应用程序放入App Store,则必须在iTunes Connect的应用程序配置中输入EULA.

Note that if you want to use a custom end-user license agreement (EULA), and you want to put this app in the App Store, you must enter the EULA in your app configuration in iTunes Connect.

这篇关于我应该如何存储一个大字符串,例如用户协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆