Good day! The problem is that through delegation I successfully pass all the data of the weatherData instance of WeatherData class, EVERYTHING except the array :( The array comes empty and I cannot understand what the problem is. Memory allocated.

Here is a snippet of code.

WeatherData *weatherData = [[WeatherData alloc] init]; if (dicJSON != nil) { float currentTempC = [[[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_CURRENT_TEMP_C] floatValue]; int roundCurrentTempC = currentTempC; NSString *currentTempCString = [NSString stringWithFormat:@"%d", roundCurrentTempC]; weatherData.city = [[[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_DISPLAY_LOCATION] objectForKey: KEY_CITY]; weatherData.country = [[[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_DISPLAY_LOCATION] objectForKey: KEY_COUNTRY]; weatherData.currentTempC = currentTempCString; weatherData.currentTempF = [[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_CURRENT_TEMP_F]; weatherData.weatherDescription = [[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_WEATHER_DESCRIPTION]; weatherData.realFeelTempC = [[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_REALFEEL_TEMP_C]; weatherData.humidity = [[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_HUMIDITY]; weatherData.windspeedkph = [[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_WIND_KPH]; weatherData.visibilityKm = [[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_VISIBILITY_KM]; weatherData.fallout = [[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_FALLOUT]; weatherData.iconCurrentWeather = [[dicJSON objectForKey: KEY_CURRENT_OBSERVATION] objectForKey: KEY_ICON]; //////// if (hourlyDicJSON != nil) { WeatherData *weatherData = [[WeatherData alloc] init]; NSArray *hourlyArr = [hourlyDicJSON objectForKey: @"hourly_forecast"]; // NSMutableArray *parsedHourlyArr = [[NSMutableArray alloc] init]; NSUInteger count = [hourlyArr count]; for (NSUInteger i = 0; i < count; i++) { NSDictionary *hourDict = hourlyArr[i]; NSMutableDictionary *hourParsedDict = [[NSMutableDictionary alloc] init]; NSString *hour = [[hourDict objectForKey: @"FCTTIME"] objectForKey: @"hour"]; NSString *temp = [[hourDict objectForKey: @"temp"] objectForKey: @"metric"]; NSString *icon = [hourDict objectForKey: @"icon"]; [hourParsedDict setObject: hour forKey: @"hour"]; [hourParsedDict setObject: temp forKey: @"temp"]; [hourParsedDict setObject: icon forKey: @"icon"]; [weatherData.parsedHourlyArr insertObject: hourParsedDict atIndex: i]; } NSLog(@"PARSED HOURLY ARRAY\n\n\n%@", weatherData.parsedHourlyArr); NSLog(@"HOURLY COUNT ELEMENTS %lu", weatherData.parsedHourlyArr.count); } [_delegate weatherDownloaderCallback: weatherData]; 

At the parish so.

NSLog(@"SetupWithActuallyDataFORECASTVIEW\n %lu", (unsigned long)data.parsedHourlyArr.count); NSLog(@"JEJEJE %@", data.currentTempC );

currentTempC is excellent, but parsedHourlyArr.count is zero :( Help please!

  • In the code you provided, you do not allocate memory for weatherData.parsedHourlyArr. weatherData.parsedHourlyArr == nil, so weatherData.parsedHourlyArr insertObject: does nothing. Create weatherData.parsedHourlyArr = [NSArray mutableArray] before looping. - Anastasia
  • NSMutableArray documentation states that in the insertObject:atIndex: index should not exceed the number of elements in the array, that is, it does nothing in your case. I'll go try addObject: instead. - Max Mikheyenko

0