I really tried not to ask the question here but after hours of trying, I'm stuck. So here goes... hopefully I can be clear.
My desired output is this:
({
following = "";
followingMe = "";
},{
following = "";
followingMe = "";
},{...})
The data coming in looks like this and what I want to do is sort it
({
user = "me";
following = "sam";
},{
user = "sam";
following = "me";
},{
user = "foo";
following = "me";
},{
user = "me";
following = "bar";
},...)
I want to organize it so if I'm following "sam" and he's following me, it's one dictionary. If "foo" is following me, then following="(null)
" and followingMe="sam"
...and so on. That's why I didn't want to ask the question... it's hard to explain.
Here's the code I have but it just gives me the last entry over and over...what's the typo?
NSMutableDictionary *temp = [NSMutableDictionary new];
int i = 0;
while (i < array.count) {
[temp removeAllObjects];
if ([[[array objectAtIndex:i]valueForKey:@"user"]isEqualToString:_user]){
//means I'm following this person
[temp setValue:[[array objectAtIndex:i] valueForKey:@"following"] forKey:@"following"];
if ([[_allfriends valueForKey:@"followingMe"]containsObject:[[array objectAtIndex:i] valueForKey:@"following"]]) {
//check to see if this person is already following me
[[_allfriends objectAtIndex:[[_allfriends valueForKey:@"followingMe"] indexOfObject:
[[array objectAtIndex:i] valueForKey:@"following"]]] setObject:[[array objectAtIndex:i] valueForKey:@"following"] forKey:@"following"];
//trying to update at the index where this person is following me
}else{
[temp setObject:@"(null)" forKey:@"followingMe"];
[_allfriends addObject:temp];
}
}else{
//this person is following me
[temp setObject:[[array objectAtIndex:i]valueForKey:@"user"] forKey:@"followingMe"];
if ([[_allfriends valueForKey:@"following"]containsObject:[[array objectAtIndex:i] valueForKey:@"user"]]) {
//check to see if I'm following this pseron
[[_allfriends objectAtIndex:[[_allfriends valueForKey:@"following"] indexOfObject:
[[array objectAtIndex:i] valueForKey:@"user"]]] setObject:[[array objectAtIndex:i] valueForKey:@"user"] forKey:@"followingMe"];
//try to update followingMe at that index
}else{
[temp setObject:@"(null)" forKey:@"following"];
[_allfriends addObject:temp];
}
}
i++;
}
So the logic is I'm checking where my name is (user
or following
). Then I'm checking if the person is already followingMe
. It it's an entry in the _allfriends
, I need to get that index and I want to update the "following
"...makes sense? What am I doing wrong here?