Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "stringWithContentsOfURL" replacement for objective C?

I found a tutorial on the net that uses the stringWithContentsOfURL command that is now deprecated as of iPhone OS 3.0. However I can't find out what I'm meant to use instead, and how to implement it.

Below is the code surrounding the stringWithContentsOfURL line in case you need it for reference.

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",       [addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]]; NSArray *listItems = [locationString componentsSeparatedByString:@","]; 

Thanks.

like image 728
Graeme Avatar asked Jan 11 '10 00:01

Graeme


2 Answers

Thanks Greg, but for all those other beginners here is an example

NSError* error = nil; NSString* text = [NSString stringWithContentsOfURL:TheUrl encoding:NSASCIIStringEncoding error:&error]; if( text ) {     NSLog(@"Text=%@", text); } else  {     NSLog(@"Error = %@", error); } 
like image 141
bstoney Avatar answered Sep 20 '22 09:09

bstoney


It has been replaced with stringWithContentsOfURL:encoding:error: or stringWithContentsOfURL:usedEncoding:error:.

like image 26
Greg Martin Avatar answered Sep 22 '22 09:09

Greg Martin