0

I'm trying to get some data from an array and print it on a UILabel in Xcode, but I get the warning:

Incompatible pointer types assigning to 'NSString *' from 'NSArray *'

Here is my code:

NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves  error:&myError];
NSArray *results =  [res objectForKey:@"current_observation"];
NSArray *cur = [results valueForKey:@"weather"];
NSArray *tmp = [results valueForKey:@"temp_c"];
NSLog(@"Current conditions: %@, %@º", cur, tmp);

temp.text = (@"%@", tmp);
4
  • 1
    temp.text = [tmp description]; Commented May 13, 2013 at 10:46
  • 3
    The description method should never be used to show the result to the user. The description method is only to be used for debugging purposes. The output of the description method for any class is rarely documented and could change in the future. Commented May 13, 2013 at 16:44
  • @rmaddy So what method should I use? Commented May 14, 2013 at 11:03
  • @Supertecnoboff It depends on how you wish to format the contents of the array. The answer by Ahmed is one solution (though I would use a comma to separate the values instead of the empty string). Commented May 14, 2013 at 17:21

1 Answer 1

3

Instead of this:

temp.text = (@"%@", tmp);

Use this:

temp.text = [tmp componentsJoinedByString:@""];
Sign up to request clarification or add additional context in comments.

7 Comments

I used @creker answer because your code made my app crash. Still trying to figure out why. But thanks for your help anyway :)
well no problem with that but plz find out whu its crashing as it should not crash at all on this
By the way I figured out what was wrong. And this solution is obviously was better than using the description method as that may change. Thanks :)
heheh :) I do this sometimes. Reply to message and so on for fun... :)
You want to combine NSStrings?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.