我想用Facebook的用户生日日期过滤NSMutableArray
。
我可以使用NSPredicate
吗?我的NSLog"结果"是:
"birthday": "05/24/1993",
"id": "xxxxxxxxxxx""
我只想" 05/24/1993获取生日日期并将其保存在NSArray
:生日。
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
FBRequest *friendRequest = [FBRequest requestForGraphPath:@"/me?fields=birthday"];
[ friendRequest startWithCompletionHandler:^(FBRequestConnection *connection,id result, NSError *error) {
[[NSUserDefaults standardUserDefaults]setObject:result forKey:@"birthdayDate"];
self.birthdayArray=[[NSUserDefaults standardUserDefaults]objectForKey:@"birthdayDate"];
NSPredicate *aPredicate = [NSPredicate predicateWithFormat:@"SELF contains[c] '/'"];
self.birthday = [self.birthdayArray filteredArrayUsingPredicate:aPredicate];
NSLog(@"BIRTHDAY : %@", self.birthday);
}
和 NSArray生日的NSLog是错误的:
-[__NSCFDictionary filteredArrayUsingPredicate:]: unrecognized selector sent to instance 0x10f80a570
答案 0 :(得分:0)
您的结果是NSDictionary
实例,而不是NSArray
实例。这就是为什么你收到错误消息,因为NSDictionary
不支持filteredArrayUsingPredicate
消息。
您可以获得包含NSDictionary中所有密钥的NSArray
:
NSArray *keys = [result allKeys];
像你一样过滤数组:
NSArray *filteredKeys = [keys filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] 'b'"]];
然后使用filteredKeys
从字典中提取所需的值:
for (NSString *key in filteredKeys) { // Assuming that the dictionary keys are string
id value = [result objectForKey:key];
NSLog(@"Current value for key %@ = %@", key, value);
}