-
对数组里面的字符串做大小写转换 注:只对字符串有效
NSArray *array = @[@"XIAOming", @"xiaohua", @"zhangshan", @"lisi", @"777"];
NSLog(@"%@", [array valueForKey:@"uppercaseString"]);
NSLog(@"%@", [array valueForKey:@"lowercaseString"]);
大小写转换结果
-
返回每个字符串长度的组成的数组 注:只对字符串有效
NSArray *array = @[@"XIAOming", @"xiaohua", @"zhangshan", @"lisi", @"777"];
NSLog(@"%@", [array valueForKey:@"length"]);
字符串长度
NSArray *array = @[@"1", @"1", @1, @"hehe"];
NSLog(@"\n%@\n%@\n%@\n%@",
[array valueForKeyPath:@"@sum.floatValue"],
[array valueForKeyPath:@"@avg.floatValue"],
[array valueForKeyPath:@"@max.floatValue"],
[array valueForKeyPath:@"@min.floatValue"]);
数组求和、平均数、最大值、最小值
NSArray *array = @[@"1", @"1", @1, @"hehe"];
NSLog(@"%@", [array valueForKeyPath:@"@distinctUnionOfObjects.self"]);
删除重复数据
NSArray *array = @[@{@"name" : @"xiaoming",
@"code" : @1},
@{@"name": @"judy",
@"code" : @2},
@{@"name": @"judy",
@"code" : @3},
@{@"name": @"xiaohua",
@"code" : @4},
@{@"name": @"xiaoming",
@"code" : @4}];
NSLog(@"%@", [array valueForKeyPath:@"name"]);
快速找出字典数组key对应的值
NSArray *array = @[@{@"name" : @"xiaoming",
@"code" : @1},
@{@"name": @"judy",
@"code" : @2},
@{@"name": @"judy",
@"code" : @3},
@{@"name": @"xiaohua",
@"code" : @4},
@{@"name": @"xiaoming",
@"code" : @4}];
NSLog(@"%@", [array valueForKeyPath:@"@distinctUnionOfObjects.name"]);
删除重复的数据,嵌套版
NSArray *temp1 = @[@3, @2, @2, @1];
NSArray *temp2 = @[@3, @4, @5];
NSLog(@"\n%@",[@[temp1, temp2] valueForKeyPath:@"@distinctUnionOfArrays.self"]);
NSLog(@"\n%@",[@[temp1, temp2] valueForKeyPath:@"@unionOfArrays.self"]);
将多个数组去重合并和直接合并
网友评论