If you're talking about -initWithContentsOfURL:
from NSString
, it has been deprecated.
But even if you are using it, it's a synchronous method - meaning your code will halt until the data has been loaded into the resulting NSString
object:
NSURL *url = [NSURL URLWithString:@"http://google.com"];
NSString *htmlData = [NSString stringWithContentsOfURL:url];
NSLog(@"%@", htmlData); // you have your data loaded here, synchronously.
So, just to be clear: this is a bad practice for two reasons:
- You're using a deprecated method which will most likely be removed on future SDK versions, and;
- You're freezing your UI while loading something from the network, while giving no feedback to the user whatsoever.
What you need is probably NSURLRequest
to create your request object and NSURLConnection
to actually load it from the network.