把删除数组里面字典文件,然后进行倒叙,删除指定的数组元素ios考核第四题
#import <Foundation/Foundation.h>
#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])
int main(int argc, const char * argv[]) {
@autoreleasepool {
//1.对字符串“2015-09-01 08:19:10”操作,输出"08:19:10"。要求使用两种截取方式。
NSString* str =@"2015-09-01 08:19:10";
//第一种方法
NSString* str1 = [str substringFromIndex:11];
NSLog(@"%@",str1);
//第二种方法
NSRange range = NSMakeRange(11, 8);
NSString* str2 = [str substringWithRange:range];
NSLog(@"%@",str2);
/*2.数组中存取以下数据:
@[@{@"name":@"陈丰",@"age":@"32"},
@{@"name":@"孙明",@"age":@"24"},
@{@"name":@"王明",@"age":@"12"},
@{@"name":@"李西",@"age":@"50"}
]
1)按年龄进行排序(降序),输出数据
2)删除“陈丰”并输出数据
*/
NSArray* array = @[@{@"name":@"陈丰",@"age":@"32"},
@{@"name":@"孙明",@"age":@"24"},
@{@"name":@"王明",@"age":@"12"},
@{@"name":@"李西",@"age":@"50"}
];
NSArray* array2 = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
int object1 = [obj1[@"age"]intValue];
int object2 = [obj2[@"age"]intValue];
if(object1==object2)
{
return NSOrderedSame;
}
else if (object1<object2)
{
return NSOrderedDescending;
}
else
{
return NSOrderedAscending;
}
}];
NSLog(@"降序后🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀");
for (id obj in array2)
{
NSDictionary* dic = obj;
NSLog(@"%@ %@",dic[@"name"],dic[@"age"]);
}
NSMutableArray* array3 =[NSMutableArray arrayWithArray:array2];
for (int i =0 ;i<array3.count;i++)
{
NSDictionary* dic = array3[i];
if([dic[@"name"]isEqual:@"陈丰"])
{
[array3 removeObject:dic];
}
//NSLog(@"%@ %@",dic[@"name"],dic[@"age"]);
}
NSLog(@"🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀🍀");
for (id obj in array3)
{
NSDictionary* dic = obj;
NSLog(@"%@ %@",dic[@"name"],dic[@"age"]);
}
}
return 0;
}