Question

I have a uicollectionView which display items from dictionaries (contained in a main dictionary in a plist). I need to sort it with the key "order" which is inside my dictionaries. I can't figure how to do this. I try to compare keys without success using descriptors.

I take the values from nsmutablearrays to display them in the cell.

Here my code (the one thart working unsorted):

//To retreive the data from the plist
NSMutableDictionary *items = [[NSMutableDictionary alloc] initWithContentsOfFile: finalPath];

//initialize arrays

_order = [[NSMutableArray alloc]initWithCapacity:10];
_name = [[NSMutableArray alloc]initWithCapacity:10];
_role = [[NSMutableArray alloc]initWithCapacity:10];
_image = [[NSMutableArray alloc]initWithCapacity:10];
_description = [[NSMutableArray alloc]initWithCapacity:10];
_email = [[NSMutableArray alloc]initWithCapacity:10];
_googleplus = [[NSMutableArray alloc]initWithCapacity:10];

//load every NSDictionnary on the view

NSMutableDictionary *loadedItem = [[NSMutableDictionary alloc]initWithCapacity:1];
NSMutableDictionary *theMember = [[NSMutableDictionary alloc]initWithCapacity:10];

loadedItem = [items objectForKey:@"Team"];

for (int i = 0; i < loadedItem.count; i++) {

    theMember = loadedItem.allValues[i];

    NSString *memberOrder = [theMember objectForKey:@"order"];
    [_order addObject:memberOrder];
    NSLog(@"member order = %@", _order);

    NSString *memberName = [theMember objectForKey:@"name"];
    [_name addObject:memberName];
    NSLog(@"member name = %@", _name);

    NSString *memberRole = [theMember objectForKey:@"role"];
    [_role addObject:memberRole];
    NSLog(@"member role = %@", _role);

    NSString *memberImage = [theMember objectForKey:@"image"];
    [_image addObject:memberImage];
    NSLog(@"member image = %@", _image);

    NSString *memberDesc = [theMember objectForKey:@"description"];
    [_description addObject:memberDesc];
    NSLog(@"member description = %@", _description);

    NSString *memberMail = [theMember objectForKey:@"email"];
    [_email addObject:memberMail];
    NSLog(@"member mail = %@", _email);

    NSString *memberGoogleplus = [theMember objectForKey:@"googleplus"];
    [_googleplus addObject:memberGoogleplus];
    NSLog(@"member googleplus = %@", _googleplus);
    }
    [self.collectionView reloadData];

}
Was it helpful?

Solution

I dealt with this by changing my mai ndict into an array which is better to manipulate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top