ios - NSPredicate in NSArray, contains number with "/" -


i filter nsmutablearray birthday date of user facebook. can use nspredicate ? nslog of "result" :

"birthday": "05/24/1993",    "id": "xxxxxxxxxxx"" 

i "05/24/1993 getting birthday date , saves in nsarray : birthday.

here code :

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

and my nslog of nsarray birthday error :

-[__nscfdictionary filteredarrayusingpredicate:]: unrecognized selector sent instance 0x10f80a570 

your result nsdictionary instance , not nsarray instance. thats why error message since nsdictionary not support filteredarrayusingpredicate message.

you can nsarray containing keys nsdictionary:

nsarray *keys = [result allkeys]; 

filter array did :

nsarray *filteredkeys = [keys filteredarrayusingpredicate:[nspredicate predicatewithformat:@"self beginswith[c] 'b'"]]; 

and use filteredkeys extract required value(s) dictionary :

for (nsstring *key in filteredkeys) { // assuming dictionary keys string     id value = [result objectforkey:key];     nslog(@"current value key %@ = %@", key, value); } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -