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];

    
    

查看全文
  • 相关阅读:
    84. Largest Rectangle in Histogram (Solution 2)
    84. Largest Rectangle in Histogram (Solution 1)
    73. Set Matrix Zeroes
    【JavaScript】Symbol 静态方法
    【JavaScript】Date
    【JavaScript】Math
    725. Split Linked List in Parts把链表分成长度不超过1的若干部分
    791. Custom Sort String字符串保持字母一样,位置可以变
    508. Most Frequent Subtree Sum 最频繁的子树和
    762. Prime Number of Set Bits in Binary Representation二进制中有质数个1的数量
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10491659.html
  • Copyright © 2011-2022 走看看