Filter array by first letter of string property

后端 未结 6 933
别那么骄傲
别那么骄傲 2020-12-06 05:09

I have an NSArray with objects that have a name property.

I would like filter the array by name

    NSString          


        
6条回答
  •  臣服心动
    2020-12-06 05:59

    If you want to filter array take a look on this code:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", @"qwe"];
    NSArray *result = [self.categoryItems filteredArrayUsingPredicate:predicate];
    

    But if you want to sort array take a look on the following functions:

    - (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context;
    - (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context hint:(NSData *)hint;
    - (NSArray *)sortedArrayUsingSelector:(SEL)comparator;
    

提交回复
热议问题