Search code examples
iosobjective-cuitableviewnsmutablearraynsarray

NSArray with several Keys to TableView


I've a weather app I'm working on. I get the Forecast data pulled in, which has an NSArray for each day of the forecast. The array looks like this:

(
        {
        apparentTemperatureMax = "73.44";
        apparentTemperatureMaxTime = 1467500400;
        apparentTemperatureMin = "47.12";
        apparentTemperatureMinTime = 1467457200;
        cloudCover = "0.75";
        dewPoint = "43.53";
        humidity = "0.58";
        icon = rain;
        moonPhase = "0.9399999999999999";
        ozone = "276.53";
        precipIntensity = "0.0036";
        precipIntensityMax = "0.0092";
        precipIntensityMaxTime = 1467504000;
        precipProbability = "0.44";
        precipType = rain;
        pressure = "1015.28";
        summary = "Light rain starting in the afternoon.";
        sunriseTime = 1467460332;
        sunsetTime = 1467513207;
        temperatureMax = "73.44";
        temperatureMaxTime = 1467500400;
        temperatureMin = "47.12";
        temperatureMinTime = 1467457200;
        time = 1467439200;
        windBearing = 281;
        windSpeed = "0.54";
    }
)

I take all the days and combine them into one giant NSMutableArray. What I want to do is to take that NSMutableArray for the Source of the UITableView, but only put in some of the weather data, like temperatureMin, temperatureMax, precipProbability, and so on. What would be the best way for me to take the NSMutableArray which houses several arrays, and only display some bits of information from each of those?

UPDATE:

Here is the full NSMutableArray:

(
        (
                {
            apparentTemperatureMax = "73.44";
            apparentTemperatureMaxTime = 1467500400;
            apparentTemperatureMin = "47.12";
            apparentTemperatureMinTime = 1467457200;
            cloudCover = "0.75";
            dewPoint = "43.53";
            humidity = "0.58";
            icon = rain;
            moonPhase = "0.9399999999999999";
            ozone = "276.53";
            precipIntensity = "0.0036";
            precipIntensityMax = "0.0092";
            precipIntensityMaxTime = 1467504000;
            precipProbability = "0.44";
            precipType = rain;
            pressure = "1015.28";
            summary = "Light rain starting in the afternoon.";
            sunriseTime = 1467460332;
            sunsetTime = 1467513207;
            temperatureMax = "73.44";
            temperatureMaxTime = 1467500400;
            temperatureMin = "47.12";
            temperatureMinTime = 1467457200;
            time = 1467439200;
            windBearing = 281;
            windSpeed = "0.54";
        }
    ),
        (
                {
            apparentTemperatureMax = "69.59";
            apparentTemperatureMaxTime = 1467576000;
            apparentTemperatureMin = 56;
            apparentTemperatureMinTime = 1467540000;
            cloudCover = "0.41";
            cloudCoverError = "0.35";
            dewPoint = "45.21";
            dewPointError = "10.53";
            humidity = "0.55";
            humidityError = "0.19";
            icon = "partly-cloudy-day";
            moonPhase = "0.97";
            precipType = rain;
            pressure = "1016.93";
            pressureError = "1.78";
            summary = "Partly cloudy throughout the day.";
            sunriseTime = 1467546762;
            sunsetTime = 1467599598;
            temperatureMax = "69.59";
            temperatureMaxError = "9.68";
            temperatureMaxTime = 1467576000;
            temperatureMin = 56;
            temperatureMinTime = 1467540000;
            time = 1467525600;
            visibility = 10;
            visibilityError = "1.98";
            windBearing = 217;
            windBearingError = "38.17";
            windSpeed = "6.24";
            windSpeedError = "4.9";
        }
    ),
        (
                {
            apparentTemperatureMax = "69.69";
            apparentTemperatureMaxTime = 1467662400;
            apparentTemperatureMin = "55.94";
            apparentTemperatureMinTime = 1467622800;
            cloudCover = "0.39";
            cloudCoverError = "0.35";
            dewPoint = "45.61";
            dewPointError = "9.890000000000001";
            humidity = "0.55";
            humidityError = "0.19";
            icon = "partly-cloudy-day";
            moonPhase = "0.02";
            precipType = rain;
            pressure = "1017.46";
            pressureError = "1.74";
            summary = "Partly cloudy throughout the day.";
            sunriseTime = 1467633192;
            sunsetTime = 1467685988;
            temperatureMax = "69.69";
            temperatureMaxError = "9.69";
            temperatureMaxTime = 1467662400;
            temperatureMin = "55.94";
            temperatureMinError = "9.48";
            temperatureMinTime = 1467622800;
            time = 1467612000;
            visibility = 10;
            visibilityError = 2;
            windBearing = 216;
            windBearingError = "35.68";
            windSpeed = "6.72";
            windSpeedError = "4.83";
        }
    ),
        (
                {
            apparentTemperatureMax = "69.78";
            apparentTemperatureMaxTime = 1467748800;
            apparentTemperatureMin = "56.03";
            apparentTemperatureMinTime = 1467709200;
            cloudCover = "0.39";
            cloudCoverError = "0.35";
            dewPoint = "45.91";
            dewPointError = "9.67";
            humidity = "0.5600000000000001";
            humidityError = "0.19";
            icon = "partly-cloudy-day";
            moonPhase = "0.05";
            precipType = rain;
            pressure = "1017.36";
            pressureError = "1.7";
            summary = "Partly cloudy throughout the day.";
            sunriseTime = 1467719624;
            sunsetTime = 1467772376;
            temperatureMax = "69.78";
            temperatureMaxError = "9.65";
            temperatureMaxTime = 1467748800;
            temperatureMin = "56.03";
            temperatureMinError = "9.470000000000001";
            temperatureMinTime = 1467709200;
            time = 1467698400;
            visibility = 10;
            visibilityError = 2;
            windBearing = 215;
            windBearingError = "35.59";
            windSpeed = "6.7";
            windSpeedError = "4.8";
        }
    ),
        (
                {
            apparentTemperatureMax = "69.84999999999999";
            apparentTemperatureMaxTime = 1467835200;
            apparentTemperatureMin = "56.11";
            apparentTemperatureMinTime = 1467795600;
            cloudCover = "0.4";
            cloudCoverError = "0.35";
            dewPoint = "46.2";
            dewPointError = "9.470000000000001";
            humidity = "0.5600000000000001";
            humidityError = "0.19";
            icon = "partly-cloudy-day";
            moonPhase = "0.08";
            precipType = rain;
            pressure = "1017.26";
            pressureError = "1.67";
            summary = "Partly cloudy throughout the day.";
            sunriseTime = 1467806058;
            sunsetTime = 1467858761;
            temperatureMax = "69.84999999999999";
            temperatureMaxError = "9.57";
            temperatureMaxTime = 1467835200;
            temperatureMin = "56.11";
            temperatureMinError = "9.41";
            temperatureMinTime = 1467795600;
            time = 1467784800;
            visibility = 10;
            visibilityError = 2;
            windBearing = 214;
            windBearingError = "35.54";
            windSpeed = "6.67";
            windSpeedError = "4.77";
        }
    ),
        (
                {
            apparentTemperatureMax = "69.91";
            apparentTemperatureMaxTime = 1467921600;
            apparentTemperatureMin = "56.17";
            apparentTemperatureMinTime = 1467882000;
            cloudCover = "0.41";
            cloudCoverError = "0.35";
            dewPoint = "46.47";
            dewPointError = "9.32";
            humidity = "0.57";
            humidityError = "0.19";
            icon = "partly-cloudy-day";
            moonPhase = "0.12";
            precipType = rain;
            pressure = "1017.16";
            pressureError = "1.63";
            summary = "Partly cloudy throughout the day.";
            sunriseTime = 1467892492;
            sunsetTime = 1467945146;
            temperatureMax = "69.91";
            temperatureMaxError = "9.449999999999999";
            temperatureMaxTime = 1467921600;
            temperatureMin = "56.17";
            temperatureMinError = "9.300000000000001";
            temperatureMinTime = 1467882000;
            time = 1467871200;
            visibility = 10;
            visibilityError = 2;
            windBearing = 213;
            windBearingError = "35.55";
            windSpeed = "6.63";
            windSpeedError = "4.74";
        }
    ),
        (
                {
            apparentTemperatureMax = "69.95999999999999";
            apparentTemperatureMaxTime = 1468008000;
            apparentTemperatureMin = "56.23";
            apparentTemperatureMinTime = 1467968400;
            cloudCover = "0.41";
            cloudCoverError = "0.35";
            dewPoint = "46.71";
            dewPointError = "9.23";
            humidity = "0.57";
            humidityError = "0.19";
            icon = "partly-cloudy-day";
            moonPhase = "0.15";
            precipType = rain;
            pressure = "1017.08";
            pressureError = "1.6";
            summary = "Partly cloudy throughout the day.";
            sunriseTime = 1467978927;
            sunsetTime = 1468031528;
            temperatureMax = "69.95999999999999";
            temperatureMaxError = "9.31";
            temperatureMaxTime = 1468008000;
            temperatureMin = "56.23";
            temperatureMinError = "9.17";
            temperatureMinTime = 1467968400;
            time = 1467957600;
            visibility = 10;
            visibilityError = "2.01";
            windBearing = 212;
            windBearingError = "35.64";
            windSpeed = "6.57";
            windSpeedError = "4.71";
        }
    ),
        (
                {
            apparentTemperatureMax = "69.98999999999999";
            apparentTemperatureMaxTime = 1468094400;
            apparentTemperatureMin = "56.26";
            apparentTemperatureMinTime = 1468054800;
            cloudCover = "0.42";
            cloudCoverError = "0.35";
            dewPoint = "46.94";
            dewPointError = "9.18";
            humidity = "0.57";
            humidityError = "0.19";
            icon = "partly-cloudy-day";
            moonPhase = "0.18";
            precipType = rain;
            pressure = "1017.01";
            pressureError = "1.58";
            summary = "Partly cloudy throughout the day.";
            sunriseTime = 1468065364;
            sunsetTime = 1468117908;
            temperatureMax = "69.98999999999999";
            temperatureMaxError = "9.17";
            temperatureMaxTime = 1468094400;
            temperatureMin = "56.26";
            temperatureMinError = "9.029999999999999";
            temperatureMinTime = 1468054800;
            time = 1468044000;
            visibility = 10;
            visibilityError = "2.01";
            windBearing = 211;
            windBearingError = "35.84";
            windSpeed = "6.48";
            windSpeedError = "4.68";
        }
    )
)

Solution

  • There are two ways to use array in the source of table.

    1- you can get the value from the array - Ex-

    NSString * temperatureMax_Str = [NSString stringWithFormat:@"%@",[[Array objectAtIndex:indexPath.row] valueForKey:@"temperatureMax"]];
    

    2- create a NSDictionary and add the value from array -

    NSDictionary *Dic = [Array objectAtIndex:indexPath.row];
     NSString * temperatureMax_Str = [Dic  valueForKey:@"temperatureMax"];
    

    Some other ways also there , You can try that also like creating mutable dictionary etc.