Tuesday, 1 September 2015

NSArray Predictive Search

+(NSMutableArray *)searchPredictive:(NSMutableArray *)array andkey:(NSString *)key andSearchText:(NSString *)search{
   
    static NSMutableArray  *resultObjectsArray = nil ;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        resultObjectsArray = [NSMutableArray array];
        for(NSDictionary *dic in array)
        {
            NSString *str = [dic objectForKey:key];
            NSRange range = [str rangeOfString:search options:NSCaseInsensitiveSearch];
            if(range.location == 0)
            [resultObjectsArray addObject:dic];
        }
    });
    return resultObjectsArray ;
}

No comments:

Post a Comment