views:

74

answers:

1

Hi folks, I'm looking for a "did finish, or finish" thing in NSURL -> NSstring initWithContentsOfUrl

i found "URLResourceDidFinishLoading" but this seems to be depreciated

I couldn't find any but maybe I searced for the wrong thing.

Thanks in advance Alex

+1  A: 

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:

  1. You're using a deprecated method which will most likely be removed on future SDK versions, and;
  2. 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.

leolobato
thanks, good to know.i haven't seen that "initWithContentsOfURL" has also been deprecatedexactly what i'm looking for.
Alex Milde