Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove NULL values from NSMutableArray? ios

i have array of birthdates as array is getting filled from facebook so there are some friends whos birthdates are private so it contain NULL how to convert that array like empty string wherever there is null value the array is like below

"<null>",
"10/29/1988",
"11/13",
"03/24/1987",
"04/25/1990",
"03/13",
"01/01",
"<null>",
"12/15/1905",
"07/10",
"11/02/1990",
"12/30/1990",
"<null>",
"07/22/1990",
"01/01",
"07/17/1989",
"08/28/1990",
"01/10/1990",
"06/12/1990",
like image 320
Prakash Desai Avatar asked Mar 08 '13 10:03

Prakash Desai


2 Answers

The null values appear to be string literals @"<null>" rather than the NSNull objects typically used to represent nils in Cocoa collections. You can filter them out by using NSArray's filteredArrayUsingPredicate method:

NSArray *filtered = [original filteredArrayUsingPredicate:pred];

There are several ways of making the pred, one of them is

NSPredicate *pred = [NSPredicate predicateWithBlock:^BOOL(id str, NSDictionary *unused) {
    return ![str isEqualToString:@"<null>"];
}];
like image 145
Sergey Kalinichenko Avatar answered Sep 20 '22 16:09

Sergey Kalinichenko


You have to use this to remove the actual [NSNull null] value.

 [array removeObjectIdenticalTo:[NSNull null]];
like image 20
davis Avatar answered Sep 20 '22 16:09

davis