How do I sort an NSMutableArray with custom objects in it?

前端 未结 27 3245
予麋鹿
予麋鹿 2020-11-21 04:45

What I want to do seems pretty simple, but I can\'t find any answers on the web. I have an NSMutableArray of objects, and let\'s say they are \'Person\' objects

27条回答
  •  情深已故
    2020-11-21 05:00

    I tried all, but this worked for me. In a class I have another class named "crimeScene", and want to sort by a property of "crimeScene".

    This works like a charm:

    NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"crimeScene.distance" ascending:YES];
    [self.arrAnnotations sortUsingDescriptors:[NSArray arrayWithObject:sorter]];
    

提交回复
热议问题