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.

Mithuzz
  • 1,091
  • 14
  • 43

2 Answers2

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;
KIDdAe
  • 2,714
  • 2
  • 22
  • 29
  • thanks for your response,but what should i do in the implementation part for sorting? – Mithuzz Oct 21 '11 at 05:15
  • 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" – KIDdAe Oct 21 '11 at 07:55
  • 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? – Mithuzz Oct 21 '11 at 09:02
  • you should take a look at http://stackoverflow.com/questions/805547/how-to-sort-an-nsmutablearray-with-custom-objects-in-it this is what you will have to do to sort your array of custom objects – KIDdAe Oct 21 '11 at 09:24
1

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

rjp
  • 1,942
  • 12
  • 14
  • 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. – Mithuzz Oct 21 '11 at 05:14