0

In my iOS app I'm using the weather APIs of worldweatheronline.com but I get a random "EXC_BAD_ACCESS" error oh this row (not always but sometimes) :

temperature.text = [NSString stringWithFormat:@"%@ °C", tempC];

Here is my code:

- (void)showWeatherFor:(CLLocation *)newLocation
{
NSString *myRequestString = [[NSString alloc] initWithFormat:@"http://api.worldweatheronline.com/free/v1/weather.ashx?q=%f,%f&format=json&num_of_days=5&key=ydvgep8jn5m846upd8kb2qp6", newLocation.coordinate.latitude, newLocation.coordinate.longitude];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:myRequestString]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *JsonString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *theDictionary = [NSDictionary dictionaryWithJSONString:JsonString error:&error];
NSDictionary *data = [theDictionary objectForKey:@"data"];
NSArray *currentDictionary = [data objectForKey:@"current_condition"];
NSDictionary *temp = [currentDictionary objectAtIndex:0];

if ([temp objectForKey:@"temp_C"] == nil || [temp objectForKey:@"temp_F"] == nil)
{
    return;
    termometro.alpha = 0;
}
else
{
    if (temp != nil)
    {
        if ([mainDelegate.gradi isEqualToString: @"°C"])
        {
            NSNumber *tempC = [temp objectForKey:@"temp_C"];
            temperature.text = [NSString stringWithFormat:@"%@ °C", tempC];
            mainDelegate.temperature = [[temp objectForKey:@"temp_C"]intValue];
        }
        else
        {
            NSNumber *tempF = [temp objectForKey:@"temp_F"];
            temperature.text = [NSString stringWithFormat:@"%@ °F", tempF];
            mainDelegate.temperature = [[temp objectForKey:@"temp_F"]intValue];
        }
        termometro.alpha = 1;
    }
}

}

swifferina
  • 293
  • 4
  • 16
  • [Enable NSZombie in XCode](http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode) and check why its `EXC_BAD_ACCESS` – Hemang Sep 07 '13 at 07:06
  • But with simulator there is no crash...I need NSZombie using my iPhone device...but it's not possible, right? – swifferina Sep 07 '13 at 09:34
  • It's possible, you can do test your app directly in your iPhone device same like you do in the simulator. It will stop at the point when an exception will generate. – Hemang Sep 07 '13 at 09:36
  • The console message is : *** -[NSConcreteMutableAttributedString dealloc]: message sent to deallocated instance 0x17e1b270 – swifferina Sep 07 '13 at 17:19

0 Answers0