Pierre
Pierre

Reputation: 160

If statement to json value

I´m trying to do an If statement from my viewcontroller to my weathercondition.m in which the web service is gathering weather information. It picks up the json from openweathermap API and shows the correct temperature in my app. However I would like to do an If statement to the temperature - like if it´s below 10 Celcius - a label can write out: "It is cold".

When I do this: newsCondition is from weathercondition.m

     if (newsCondition.temperature.floatValue == 0) {
         [label1 setText:@"It´s really cold today!"];

The label shows in the app but says "It´s really cold today" even though the temperature isn´t zero. Does anyone know how to write the If statement to compare it to the number parsed from the json?

Upvotes: 0

Views: 86

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89509

"floatValue" isn't a property.

Why not change your code to something like:

if ([newsCondition.temperature floatValue] <= 0.0f)
{
    [label1 setText:@"it's really cold today!"];
} 
else
{
    [label1 setText:@""];
}

You'll also see I set the label to be blank if the temperature is greater than 0. That's because table view cells (which is what I suspect you are using here) get recycled when old ones scroll out of view.

Upvotes: 2

Related Questions