0

Here I having two arrays, one array contains names and the other contains some links. I done sorting of name array, but i need to sort the link array with respect to the changes in the name array. I got a method when I went through the documents and that is:

-(void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject{

}

But I don't know how to implement it. Please give any sample code to implement it. I'm not usre it is the right way to do. If there is any please help me.

Thanks.

2 Answers 2

1

Is there a reason you can't combine the name and link in a struct or object for sorting together?

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

1 Comment

No, I just need a solution, I don't know how to do that. I'm looking for a better way to solve the issue.
1

This method is already implemented for NSMutableArray, why would you overload it ? I think you should create a new class with 2 properties (name and link) and store this class in a unique Array.

@interface myObject {
NSString *name;
NSString *link;
}

@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *link;

4 Comments

thanks for your response,but what should i do in the implementation part for sorting?
You said that you had already sort your array by names ? Then you should do the same with the array containing this new class by using "myObject.name" instead of "name"
ya, I used [nameArray sortUsingSelector:@selector(caseInsensitiveCompare:)]; this to sort the array. Please show me a sample code. Implementation part and how call my array in other class files?
you should take a look at stackoverflow.com/questions/805547/… this is what you will have to do to sort your array of custom objects

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.