gpt4 book ai didi

iOS 应用程序。按字母顺序获取 Facebook 好友

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:51:22 26 4
gpt4 key购买 nike

我已成功将 iOs Facebook API 集成到我的应用程序中。现在,我想得到用户的 friend 。为了得到它,我使用:

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

然后我实现了一个委托(delegate)方法来接收它:

- (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);
}
}

所以我为用户的每个 friend 创建了对象 friend 。我正确地找到了 friend ,但顺序是随机的。

问题来了,有什么办法可以按字母顺序接收用户的好友吗?

最佳答案

与其按字母顺序接收它们,不如在下载完所有好友后重新排列好友数组。这是比较数组并按字母顺序排序的最佳方式。

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

但是如果你想通过 Friends 类的属性/变量(即 Name)来比较数组,你可以按以下方式进行:

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

关于iOS 应用程序。按字母顺序获取 Facebook 好友,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7861980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com