zoukankan      html  css  js  c++  java
  • oc描述器排序

    int main(int argc, const char * argv[]) {

        @autoreleasepool {

            

            NSArray *array = @[CreateDict(@"王思聪", 27, YES),

                               CreateDict(@"范冰冰", 35, NO),

                               CreateDict(@"马云", 51, YES),

                               CreateDict(@"霍建华", 36, YES),

                               CreateDict(@"赵丽颖", 28, NO)];

         

            

           //第1题 请按照年龄的升序排序输出,输出样式为:王思聪,男性,今年27岁

            

            

           

            NSSortDescriptor *ageWithSort=[[NSSortDescriptor alloc]initWithKey:kAge ascending:YES];

            NSArray *elementarr=[NSArray arrayWithObjects:ageWithSort,nil];

            

            NSArray *sortArray=[array sortedArrayUsingDescriptors:elementarr];

            NSLog(@"第一题");

            NSLog(@"排序后:");

            

            for (NSDictionary *dic in sortArray) {

                

                int i=[dic[@"gender"]intValue];

            

                if (i==1) {

                    NSString *str=@"男性";

                    NSLog(@"%@,%@,今年%@岁",dic[kName],str,dic[kAge]);

                }

                if (i==0) {

                    NSString *str1=@"女性";

                    NSLog(@"%@,%@,今年%@岁",dic[kName],str1,dic[kAge]);

                }

               }

  • 相关阅读:
    小程序解析html(使用wxParse)
    error: the HTTP rewrite module requires the PCRE library
    CMake Error at cmake/boost.cmake:76 (MESSAGE)
    Centos7安装mysql后无法启动,提示 Unit mysql.service failed to load:No such file or directory
    mysql的三种安装方式
    epel源
    cmake
    yum
    wget
    tar指令
  • 原文地址:https://www.cnblogs.com/shaowenlong/p/5121900.html
Copyright © 2011-2022 走看看