1.字符串升降序
// ascending:YES升序 NO降序
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];
NSArray *descriptors = [NSArray arrayWithObject:descriptor];
NSArray *myDataArray = [NSArray arrayWithObjects:@"account3rd", @"login_type", nil];
NSArray *resultArray = [myDataArray sortedArrayUsingDescriptors:descriptors];
NSLog(@"%@", resultArray);
NSString * resultStr = [[NSString alloc] init];
for (NSString * str in resultArray) {
resultStr = [resultStr stringByAppendingString:str];
}
NSString * lastStr = [NSString stringWithFormat:@"%@%@", APPKEY, resultStr];
NSLog(@"===%@===", lastStr);
最后打印(
account3rd,
"login_type"
)
2.字符串值比较
NSArray *array = [NSArray arrayWithObjects:@"2.0", @"2.3", @"3.0", @"4.0", @"10", nil];
//sum求和
CGFloat sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue];
//avg求平均值
CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
//求最大值
CGFloat max =[[array valueForKeyPath:@"@max.floatValue"] floatValue];
//求最小值
CGFloat min =[[array valueForKeyPath:@"@min.floatValue"] floatValue];
NSLog(@"sum = %f\navg = %f\nmax = %f\nmin = %f",sum,avg,max,min);
最后打印
sum = 21.299999
avg = 4.260000
max = 10.000000
min = 2.000000