开发者

What is the best way to store strings in iPhone application?

I'm wondering what is the best way to store long strings in iPhone? e.g. I have 'about' page in my app which is basically an html page, 开发者_Python百科and I load it to UIWebView.

Is there any better way so store it apart from store it as string in code? may be in resource file?

Thank you


You can add the html file directly as a resource in your bundle. Then when you want to use it you can use the following code

NSString* fileName = [[NSBundle mainBundle] fileForResource:@"myHtmlFile" withExtension:@"html"];
NSString* fileContents = [NSString stringWithContentsOfFile:fileName encoding:NSUTF8Encoding error:nil];
[webView loadHTMLString:fileContents baseURL:baseURL];


You can use a plist that is very flexible and fast to load. If you plan to localize this text into different language you should use String File (both are available under "Resource" when you choose to create a new file in xcode)


I haven't done this myself, but I'm guessing you could simply deploy an HTML file with your bundle (just add it as a resource to your project) and point the UIWebView at it.


If the string will never change throughout the life of the application, you should use a resource packaged in your application bundle.

As the previous posts alluded to, you have several options. You can make a plist, an HTML file, or any other kind of file resource.

A nice benefit of these options is that you have the ability to make localized versions.

If the string will change through use of the application, you may also consider storing the value of the string in a local database with SQLite and CoreData.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜