标签:
//
// main.m
// 数组字典结合删除排序
//
// Created by 博博 on 16/1/8.
// Copyright (c) 2016年 com.bb. All rights reserved.
//
#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSDictionary *dic1=@{@"name":@"小阳",@"class":@"IOS8",@"age":@"24"};
NSDictionary *dic2=@{@"name":@"小明",@"class":@"IOS6",@"age":@"67"};
NSDictionary *dic3=@{@"name":@"小丽",@"class":@"IOS8",@"age":@"12"};
NSDictionary *dic4=@{@"name":@"小杨",@"class":@"IOS6",@"age":@"33"};
// NSArray *dic5=@[@{@"name":@"小阳",@"class":@"IOS8",@"age":@"24"},
// @{@"name":@"小明",@"class":@"IOS6",@"age":@"67"},
// @{@"name":@"小丽",@"class":@"IOS8",@"age":@"12"},
// @{@"name":@"小杨",@"class":@"IOS6",@"age":@"33"}];
// for(int i=0;i<[dic5 count];i++)
// {
// NSDictionary *k=dic5[i];
// NSLog(@"班级:%@,姓名:%@,年龄%@",k[@"class"],k[@"name"],k[@"age"]);
// }
// NSLog(@"----\n");
NSMutableArray *muarr=[NSMutableArray array];
[muarr addObject:dic1];
[muarr addObject:dic2];
[muarr addObject:dic3];
[muarr addObject:dic4];
//for (NSDictionary *dic in muarr) {
// NSLog(@"班级:%@,姓名:%@,年龄%@",dic[@"class"],dic[@"name"],dic[@"age"]);
//}
// [muarr removeObject:dic2];
// for (NSDictionary *dic in muarr) {
// NSLog(@"班级:%@,姓名:%@,年龄%@",dic[@"class"],dic[@"name"],dic[@"age"]);
// }
NSSortDescriptor *p1=[NSSortDescriptor sortDescriptorWithKey:@"class" ascending:1];
NSSortDescriptor *p2=[NSSortDescriptor sortDescriptorWithKey:@"age" ascending:1];
NSArray *p=[muarr sortedArrayUsingDescriptors:[NSArray arrayWithObjects:p1,p2, nil]];
for (NSDictionary *dic in p) {
NSLog(@"班级:%@,姓名:%@,年龄%@",dic[@"class"],dic[@"name"],dic[@"age"]);
}
//1.将以上四个字典存入数组中,输出数据以班级:XXX,姓名:XXX,年龄:XX格式。
//2.删除小明此条数据,列出剩余数据,输出格式同上。
//3.按照班级进行排序,如果班级相同则按照年龄排序输出数据,格式同上。描述器
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/bobohahaha/p/5115535.html