NSSortDescriptor issue

前端 未结 4 1979
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 20:24

I am making a contact book App where I am fetching names from AddressBook and stored them in Core data and displayed the names on a table using NSFetchedResultsControl

4条回答
  •  走了就别回头了
    2021-01-13 21:11

    You could try writing your own comparator Function

    Assuming that it is sorting ManagedObjects and they all have fullName as a field, then the following may help.

    [[NSSortDescriptor alloc] initWithKey:@"FullName" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) {
            return [[obj1 objectForKey:@"fullName"] compare:[obj2 objectForKey:@"fullName"] options:NSCaseInsensitiveSearch];
        }];
    

    The advantage of this is you can also write the NSLog for each comparison and see what is happening.

提交回复
热议问题