NSArray subsets and sorting from a dynamic categoryArray

Discussion in 'iOS Programming' started by Sam77, Feb 6, 2012.

  1. Sam77
    Expand Collapse
    macrumors newbie

    Aug 17, 2010
    I've run into a big question of an approach in order to fuel a graph view.

    I retrieve Arrays via coredata.

    A Category <--->>Entry entity relationship exists.
    Category <-------->>Entry
    I need to combine the results of Category <-->> Entry relationship into an array sorted by NSDate, thats pretty easy, a parent could have multiple Entries based on timeStamp (NSDate) of adding it.

    I use a fetchRequest with the following:

        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    I want to have a combined result thats sorted Based on TimeStamps

    For example,

        NSArray Result_CatA = [entries sortedBy timeStamp]; {A0 ,A1, A2, A3,     A5}   (5)
        NSArray Result_CattB = [entries sortedBy TimeStamp]; {B0, B1, B2, B3, B4}       (5)
        NSArray Result_CatC = [entries sortedBy TimeStamp]; {C0, C1, C2, C3, C4  C5 }  (6)
    Two points to note here,
    1- Array Result_CatA has no entryObject on date "4th" and likewise, B array has no entry on "5th", lets assume those digits to be their NSDates of adding.

    I want to have an array that gives me a result as an Array like:

        CombinedSortedArray objectAtIndex:0] = Array{A0, B0, C0}  CountRemains 3 
        CombinedSortedArray objectAtIndex:1] = Array{A1, B1, C1}  Count remains 3
        CombinedSortedArray objectAtIndex:4] = Array{0.0, B4, C4}
        CombinedSortedArray objectAtIndex:5] = Array{A5, 0.0, C5}
        //Count of all the subset Arrays remains 3  which is equal to the count of Parents! Only the difference being that a nil result is replaced by 0.0!

    2- All this is more complicated by knowing that the Category is a dynamic number, there could be a total number of 4 categories to be presented, in which case there will be 4 arrays to parse into One, and each object of that single sorted array would have 4 object count.

    Im clueless now, any help is appreciated.

Share This Page