0

I have the following class:

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

4
  • Is there a property declaration corresponding to the mObjArr instance variable? It seems that since you're getting an "unknown getter" method that the calling code is looking for a property that either isn't declared or isn't imported in the implementation file. Commented Jun 28, 2010 at 5:33
  • 1
    It might help to show the part of the code where the error is actually occuring. Commented Jun 28, 2010 at 5:48
  • Yes, I have no property, thanks. I've added the property for the mObjArr. But I still have the problem. Programm crashes on line: [self.mObjArr sortUsingSelector:@selector(MyCompareFunc:)]; While compiling I have the warning on the line: 'NSArray' may not respond to '-sortUsingSelector:' Commented Jun 28, 2010 at 6:23
  • stackoverflow.com/questions/2849911/sorting-a-nsarray Commented Jun 28, 2010 at 12:25

1 Answer 1

2

I'm not sure if this is the only problem, but you'd need an NSMutableArray, not NSArray, to use sortUsingSelector:.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.