NSArray sort with custom objects
I have the following class:
ty开发者_C百科pedef enum eItems {
kItem1,
kItem2,
kItem3  
} MyItem;
@interface MyClass: CCSprite<CCTargetedTouchDelegate>{
... 
MyItem mClIt;
...
}
...
- (NSComparisonResult)MyCompareFunc:(MyClass*)inObject
- (MyItem)GetSomeItem;
...
And function for sorting:
- (NSComparisonResult)MyCompareFunc:(MyClass*)inObject
{
 if ([self GetSomeItem] > [inObject GetSomeItem])
    return NSOrderedDescending;
 else if ([self GetSomeItem] < [inObject GetSomeItem])
    return NSOrderedAscending;
 return NSOrderedSame;
}
I create the NSArray of the MyClass objects later in the some class:
@interface Person : Main {
    ....
    NSArray * mObjArr;
    ....
}
And I need to sort the mObjArr with help of MyCompareFunc, using  sortUsingSelector:@selector(MyCompareFunc:) method. But I have the following error:
error: accessing unknown 'mObjArr' getter method.
Help please to resolve the problem.
I'm not sure if this is the only problem, but you'd need an NSMutableArray, not NSArray, to use sortUsingSelector:.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论