//
// ViewController.m
// h
//
// Created by jason on 13-3-1.
// Copyright (c) 2013年 hufeng. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
typedef struct
{
BOOL isHasKey;
int position ;
}ReturnDate;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSDictionary *dict = @{
@"pushInfo": @[
@{
@"content": @"处理批示",
@"infoId": @"info001",
@"modeType": @"db",
@"systemType": @"oa"
},
@{
@"content": @"处理批示",
@"infoId": @"info002",
@"modeType": @"st",
@"systemType": @"oa"
},
@{
@"content": @"处理批示",
@"infoId": @"info003",
@"modeType": @"ls",
@"systemType": @"oa"
},
@{
@"content": @"处理批示",
@"infoId": @"info004",
@"modeType": @"ed",
@"systemType": @"oa"
},
@{
@"content": @"处理批示",
@"infoId": @"info002",
@"modeType": @"sd",
@"systemType": @"oa"
},
@{
@"content": @"处理批示",
@"infoId": @"info005",
@"modeType": @"sd",
@"systemType": @"oa"
},
@{
@"content": @"处理批示",
@"infoId": @"info005",
@"modeType": @"sddd",
@"systemType": @"oa"
},
@{
@"content": @"处理批示",
@"infoId": @"info006",
@"modeType": @"sddd",
@"systemType": @"oa"
},
]
};
// NSLog(@"the dict = %@" , dict);
NSArray *array = [dict objectForKey:@"pushInfo"];
[self returnKey:array key:@"info002"];
NSMutableArray *uniquarray = [NSMutableArray array];
NSMutableArray *uniquarraytmp = [[array mutableCopy]autorelease];
for (int i = [uniquarraytmp count]; i>0; i--)
{
NSString *key = [[uniquarraytmp objectAtIndex:i-1] objectForKey:@"infoId" ];
ReturnDate dt = [self returnKey:uniquarray key:key];
if(dt.isHasKey)
{
NSMutableDictionary *dictA =
[[[uniquarraytmp objectAtIndex:i-1]mutableCopy]autorelease];
NSString *a =[dictA objectForKey:@"modeType"];
NSMutableDictionary *dictB =
[[[uniquarray objectAtIndex:dt.position]mutableCopy]autorelease];
NSString *b =[dictB objectForKey:@"modeType"];
[dictA setObject:[NSString stringWithFormat:@"%@^%@",a,b] forKey:@"modeType"];
[uniquarray replaceObjectAtIndex:dt.position withObject:dictA];
}
else
{
[uniquarray addObject: [uniquarraytmp objectAtIndex:i-1]];
[uniquarraytmp removeObjectAtIndex:i-1];
}
}
NSLog(@"the after \n%@",uniquarray);
}
-(ReturnDate)returnKey:(NSArray *)array key:(id)key
{
int i =0;
ReturnDate date;
date.position =0;
date.isHasKey =NO;
for (NSDictionary *dict in array)
{
if ([[dict objectForKey:@"infoId"] isEqual:key]
)
{
date.isHasKey = YES;
date.position =i;
break;
}
else
{
i++;
}
}
return date;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
分享到:
相关推荐
Merge Sorted Array 合并 排序 数组 leetcode
1.array_merge()合并 ...上面因为都是数组就没有问题了,假如我们把$array 设置不是数组看看什么情况 $array = 1;//array('a'=>'bb'); $array2 = array('b'=>'cc'); $array3 = array_merge($array,$array2); print_r
key_exists -- 检查给定的键名或索引是否存在于数组中 array_keys -- 返回数组中所有的键名 array_map -- 将回调函数作用到给定数组的单元上 array_merge_recursive -- 递归地合并一个或多个数组 array_merge -- ...
“+”运算符和array_merge():array array_merge ( array array1, array array2 [, array ...] )都可以合并多个数组,但使用过程中有一点小区别。
本篇文章是对php中用加号与用array_merge合并数组的区别进行了详细的分析介绍,需要的朋友参考下
php数组合并 array_merge-php函数_.docx
本文实例讲述了PHP数组array类常见操作。...$result = array_merge((array)$beginning, (array)$end); print_r($result); ?> 以上例程会输出: Array ( [0] => foo [1] => bar ) 2、 <?php $a
合并数组是把一个数组追加到另一个数组中,主要应用array_merge()函数实现 语法如下: array array_merge(array array1,array array2[,array...]); 注: 在合并时,如果输入的数组中有相同的字符串键名,则后面的值...
定义:array_merge — 合并一个或多个数组 规范:array array_merge(array $array1 [, array $…]) 说明: 1. 将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。 2. 如果输入的数组中有相同...
php数组合并 array_merge-php函数__2.docx
php数组合并 array_merge-php函数__1.docx
php中array_merge_recursive函数用于将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面,返回作为结果的数组。本文章将详细介绍array_merge_recursive函数的使用方法和实例。 先来介绍一下...
php相同数据数组合并 array_merge_recursive-php函数_.docx
我感觉奇怪的地方,就是数组$array_one与数组$array_two直接进行相加操作,我之前进行数组合并操作都是按照array_merge()函数进行操作的,重来没有用到过上面的方式直接进行运算。 分析如下 下面就简单说明以下,...
in_array()定义和用法 in_array() 函数查找数组中是否存在指定值。 语法 in_array(value,array,type)参数 描述 value 必需。规定要在数组搜索的值。 array 必需。规定要搜索的数组。 type 可选。如果设置该参数为 ...
本文实例讲述了php通过array_merge()函数合并关联和非关联数组的方法。分享给大家供大家参考。具体分析如下: array_merge()是一个用于合并数组的php函数,后一个数组追加到前一个的结束位置并返回合并后的结果数组...