开发者

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:.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜