作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像这样的 NSMutableArray
。
2015-09-22 10:12:22.739 amigo[17198:6080591] Headers ************************ (
{
BidAcceptanceRide = 0;
BidRejectionRide = 1;
BidRide = 1;
BookingCancellationByBuyer = 0;
BookingCancellationBySeller = 0;
BookingConfirmation = 3;
BookingRemainder = 0;
Review = 0;
TotalNotification = 5;
}
)
我想做的是检查这些每个键值对,如果值大于 0,我想将它的键添加到另一个数组。我怎样才能做到这一点?请帮助我。
谢谢
最佳答案
您可以尝试使用以下代码
,您可以根据需要进行修改。
NSArray * arrHeaders; // Your existing array in which you have value.
NSMutableArray * arrSortedData = [NSMutableArray array]; // New array in which you will add data.
for (int i = 0; i < [arrHeaders count]; i++){
NSDictionary * dicTeamp = [arrHeaders objectAtIndex:i];
NSMutableDictionary * dicSortedData = [NSMutableDictionary dictionary]; // Dictionary where all keys and value which is greater than 0.
for (int j = 0; j < [[dicTeamp allKeys] count]; j++){
if([[dicTeamp valueForKey:[[dicTeamp allKeys] objectAtIndex:j]] intValue] > 0){
[dicSortedData setValue:[dicTeamp valueForKey:[[dicTeamp allKeys] objectAtIndex:j]] forKey:[[dicTeamp allKeys]objectAtIndex:j]];
}
}
[arrSortedData addObject:dicSortedData];
}
NSLog(@"Your sorted data = %@",arrSortedData);
关于ios - 如何将 NSMutableArray 的键添加到另一个数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32708650/
我是一名优秀的程序员,十分优秀!