I’ve written some code that uses stringWithContentsOfURL, but it turns out that it is now deprecated. Can you help me replace it? Here’s my code:
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];
Additionally, can someone have some sample code to show how it works? What encoding was the original code done in (in my 2 lines above)?
I want to maintain compatibility so what should I choose for the encoding? What does error mean and what is it used for?
Use
stringWithContentsOfURL:encoding:error:EDIT: Here’s your code using the above method:
You can change
NSUTF8StringEncodingaccordingly for whatever data you’re importing.