zoukankan      html  css  js  c++  java
  • NSArray 查询数组中的对象

    1.NSString 对象

    NSArray  *array =@["123", @"234" , @"345"];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [cd] %@", "2"];

    NSArray *filterdArray = [array filterdArrayUsingPredicate:predicate];

    NSLog(@"%@", filterdArray );
    //output : @"123", "234"
    
    
    2.含有属性的对象
    
    
    @interface Person: NSObject 
    {
        NSString *_name;
        NSString *_telephone;
        NSInteger _id;
    }
    
    @property (nonatomic, copy) NSString *name;
    @property (nonatomic, copy) NSString *telephone;
    @property (nonatomic, assign) NSInteger id;

    @end
    //
    1).
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", "Ansel"]; 
    NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];
    
    
    2).
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id== %@", @13]; //predicate仅仅能是对象
    NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];

    
    

查看全文
  • 相关阅读:
    dubbo zookeeper报错failed to connect to server , error message is:No route to host
    linux的ssh命令
    linux的/etc/hosts的作用
    linux如何查看某个pid的进程?
    Nginx配置详解
    nginx基本配置与参数说明以及Nginx中的upstream轮询机制介绍
    Nginx配置upstream实现负载均衡
    nginx简单的nginx.conf配置
    API Gateway性能比较:NGINX vs. ZUUL vs.Cloud Gateway vs. Linkerd[译]
    RabbitMQ 入门【精+转】
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10491659.html
  • Copyright © 2011-2022 走看看