views:

250

answers:

2

I'm working with an intermediate join table in Core Data similar to the friends example from Apple's Core Data Programming Guide. Sorry, can't post pictures yet due to no reputation points. Its a friends entity with relationships to FriendInfo intermediate join, with relationships of friends and friend info. The following link describes it.

link text

How would I get a list of mutual friends, ie persons both Person A and Person B share as friends? I'm looking to put this into an iPhone application table view.

Thanks for helping me with my first post... great site.

A: 

The answer is almost there in the documentation url you have given. Let's say there are two people personA and personB. You can get their respective friends by

NSSet *friendsOfPersonA = [personA valueForKeyPath:@"friends.friend"];
NSSet *friendsOfPersonB = [personB valueForKeyPath:@"friends.friend"];

Do a set intersection to find common friends

NSSet *commonFriends = [[NSMutableSet alloc] initWithSet:friendsOfPersonA];
[commonFriends intersectSet:friendsOfPersonB];

The set commonFriends should be what you want.

Note: The example Apple gives includes an additional property like befriendedBy. Usually that's not the case in online social networks such as Facebook where friendship is mutual. But if you were to go down that road and want to count a friendship only when two people are friends of each other, then it's one extra step to get there. To find the friends of a person in that case, you'd do a set intersection for a person's friends and those who have befriended him.

Anurag
Thanks for the quick reply - the intersect was what I was missing
A: 

Hi guys... i'm developing an application using Facebook Connect and i can import the friend list of any contact. Look this is my code but i have an error in the following line:

- (void)viewContacts:(id)target {
//NSMutableArray* contactList = [[[NSMutableArray alloc] init] autorelease];
NSString* fql = [NSString stringWithFormat:@"SELECT name,uid FROM user WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1=%lld )",[self fbSession].uid];
NSDictionary* contactList = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:contactList];

}

On the third line the compiler recognize and error with "fbSession" variable. Is the correct query?. Thanks and regards, Cesar.

Cesar Augusto Soto Caballero
if you want to get any sort of help, you should ask this as a new question
Anurag