Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

North Bronson

macrumors 6502
Original poster
Oct 31, 2007
395
1
San José
If I have some local HTML content that I need to load in a UIWebView, it seems like there are two ways to do it:

Code:
NSString *fileString = [[NSBundle mainBundle] pathForResource: SomeLocalHTMLFile ofType: @"html"];

NSString *newHTMLString = [[NSString alloc] initWithContentsOfFile: fileString encoding: NSASCIIStringEncoding error: NULL];

NSURL *newURL = [[NSURL alloc] initFileURLWithPath: fileString];

[myWebView loadHTMLString: newHTMLString baseURL: newURL];

OR

Code:
NSString *fileString = [[NSBundle mainBundle] pathForResource: SomeLocalHTMLFile ofType: @"html"];

NSURL *newURL = [[NSURL alloc] initFileURLWithPath: fileString];

NSURLRequest *newURLRequest = [[NSURLRequest alloc] initWithURL: newURL];

[myWebView loadRequest: newURLRequest];

Is one of these ways preferred over the other? Both seem to work.

On another note, if I do go with the first way, am I choosing the right String Encoding? I'm just loading a plain HTML file.
 
Is one of these ways preferred over the other? Both seem to work.

Basically, whichever one runs faster in a profiler. Failing that, whichever you find easier to read.

On another note, if I do go with the first way, am I choosing the right String Encoding? I'm just loading a plain HTML file.

Depends what encoding you wrote the file in. Assuming you're not doing anything special (foreign alphabets etc.), ASCII should be just fine.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.