Filter array by first letter of string property

后端 未结 6 914
别那么骄傲
别那么骄傲 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:48

    NSArray offers another selector for sorting arrays:

    NSArray *sortedArray = [array sortedArrayUsingComparator:^NSComparisonResult(Person *first, Person *second) {
        return [first.name compare:second.name];
    }];
    

提交回复
热议问题