2017-03-16 11 views
1

나는 StudentScoreObj가 들어있는 배열 (NSMutableArray)을 가지고 있으며 그 개체는 missions(NSArray)입니다.iOS 사용자 정의 객체의 NSMutableArray를 정렬하는 방법 NSNumber의 NSarray가 포함되어 있습니까?

처럼 : 선교 배열의 첫 번째 개체를 사용하여 배열의 StudentScoreObj을 정렬

missions = @[@34, @43, @54, @23, @54]; 

필요.

내 코드 :

@interface StudentScoreObj : NSObject 

@property (nonatomic, copy) NSString *teamType; 
@property (nonatomic, copy) NSString *teamNumber; 
@property (nonatomic, copy) NSString *studentName; 
@property (nonatomic, copy) NSString *isParticipated ; 
@property (nonatomic, copy) NSString *totalScore; 
@property (nonatomic, copy) NSString *avgScore; 
@property (nonatomic, copy) NSArray *missions; 

@end 
+0

어떻게 시도 했습니까? – Paulw11

답변

0

당신은 그것에 대해 sorted​Array​Using​Comparator를 사용할 수 있습니다.

NSArray *sortArray = [array sortedArrayUsingComparator:^NSComparisonResult(StudentScoreObj *obj1,StudentScoreObj *obj2) { 

    NSNumber *obj1Score = @0, *obj2Score = @0;   
    if([[obj1 missions] firstObject]) { 
     obj1Score = @([[[obj1 missions] firstObject] intValue]); 
    } 

    if([[obj2 missions] firstObject]) { 
     obj2Score = @([[[obj2 missions] firstObject] intValue]); 
    } 
    return [obj1Score compare:obj2Score]; 
}]; 
+0

그것은 작동합니다.! 감사! – PillowPig

+0

@PillowPig 환영 메이트 :) –