Sorting array of custom objects using the value of an internal object's instance variable

前端 未结 3 1112
鱼传尺愫
鱼传尺愫 2021-02-08 06:40

(sorry about the long title)

I have a custom object Person, which in turn has an NSSet which has several custom objects called Appointment. A Person therefo

3条回答
  •  囚心锁ツ
    2021-02-08 07:11

    If you have the data in an NSArray form you can sort it like this:

    NSArray *sortedPersonArray = [coreDataPersonArray sortedArrayUsingSelector:@selector(compare:)];
    
    - (NSComparisonResult)compare:(Person *)personObject {
        return [self.startSecond compare:personObject.startSecond];
    }
    

提交回复
热议问题