I have a if-else statement which isn’t quite working as I would want it to. This is the method before the statement which holds the variables:
[self.conditionsLabel setText:weather.weathercondition];
NSLog(@"%@", weather.weathercondition);
condition = weather.weathercondition;
Here is the if-else statement:
if ([weather.weathercondition isEqualToString:@"Clear"]) {
conditionsImageView.image = [UIImage imageNamed:@"Sun.png"];
}
else {
conditionsImageView.image = [UIImage imageNamed:@"Partly_Sunny.png"];
}
In my console, the weather.weathercondition comes up as clear, but when it goes through the if-else statement, it always goes to the else and shows the Partly_Sunny.png. I’m testing it right now, and I know that the string is going to be “Clear”. I am getting the data from an XML source and this is how it shows the data if I look at it on the internet :
<weatherDesc>
<![CDATA[ Clear ]]>
Is this the cause? It says the CDATA before Clear, but in the code, it always logs as Clear, without the CDATA and other things. I tried putting the <![CDATA[ Clear ]]> in the isEqualToString:, but the same results came. Any help would be greatly appreciated. I’m new to parsing XML and relatively new to Objective-C, so please excuse any errors (not in the code, but generally). I greatly appreciate the help.
The CDATA is a construct to denote that whatever inside should be treated as plain text (not XML). When XML parser detects it, it will remove the CDATA construct and present the data inside the construct.