ValentiGoClimb
ValentiGoClimb

Reputation: 750

iOS app. get Facebook friends in alphabetical order

I have integrated the iOs Facebook API into my app successfully. Now, I want to get the Friends of the users. To get it I use:

[facebook requestWithGraphPath:@"me/friends" andDelegate:self];

And I implement a the delegate method to recieved it:

- (void)request:(FBRequest *)request didLoad:(id)result {

    uids = [[NSMutableArray alloc]init];
    if([result isKindOfClass:[NSDictionary class]])
    {
        NSLog(@"dictionary %@",result);
        result=[result objectForKey:@"data"];
        if ([result isKindOfClass:[NSArray class]]) 

            for(int i=0;i<[result count];i++){

                NSDictionary *result2=[result objectAtIndex:i];
                /*NSLog(@"resultq:%@",result2);

                NSString *result1=[result2 objectForKey:@"id"];
                NSLog(@"uid:%@",result1);*/

                Friend *f = [[Friend alloc] initWithDictionary:result2];
                [uids addObject:f];
                [f release];
            }
        NSLog(@"uids %@",uids);    
    }
}

So I create the object Friend with every Friend of the user. I get the friends correctly but with a random order.

The question is, there is any way to receive the user's friends in alphabetical order?

Upvotes: 2

Views: 2971

Answers (1)

max_
max_

Reputation: 24521

Instead of receiving them in Alphabetical order, why don't you just re-arrange the array of Friends once you have downloaded all of them. This is the best way to compare an array and sort it alphabetically.

sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

But if you want to compare the array by an attribute / variable of the Friends class i.e Name, you can do it the following way:

sortedArray = [anArray sortUsingSelector:@selector(name)];

Upvotes: 4

Related Questions