如何从NSMutableArray中删除NULL值? IOS [英] how to remove NULL values from NSMutableArray? ios

查看:94
本文介绍了如何从NSMutableArray中删除NULL值? IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列的生日,因为数组正在从facebook填充所以有一些朋友,其中生日是私有的所以它包含NULL如何转换该数组像空字符串,只要有空值,数组如下所示

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",


推荐答案

null 值似乎是字符串文字 @< ; null>而不是通常用于在Cocoa中表示 nil NSNull 对象集合。您可以使用 NSArray filteredArrayUsingPredicate 方法过滤掉它们:

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];

有几种方法可以制作 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>"];
}];

这篇关于如何从NSMutableArray中删除NULL值? IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆