I am just looking at sorting an NSArray of NSNumbers into numeric order but am a little unsure of the best way to go. By my way of thinking 001 and 002 are pretty comparable, so I would suspect either will do. For 003 I am not sure if returning NSMutableArray when the method expects NSArray is good practice, it works, but it feels awkward.
-(NSArray *)testMethod:(NSArray *)arrayNumbers {
// 001
NSMutableArray *sortedArray = [NSMutableArray arrayWithArray:arrayNumbers];
[sortedArray sortUsingSelector:@selector(compare:)];
arrayNumbers = [NSArray arrayWithArray:sortedArray];
return(arrayNumbers);
}
.
-(NSArray *)testMethod:(NSArray *)arrayNumbers {
// 002
NSMutableArray *sortedArray = [NSMutableArray arrayWithArray:arrayNumbers];
[sortedArray sortUsingSelector:@selector(compare:)];
arrayNumbers = [[sortedArray copy] autorelease];
return(arrayNumbers);
}
.
-(NSArray *)testMethod:(NSArray *)arrayNumbers {
// 003
NSMutableArray *sortedArray = [NSMutableArray arrayWithArray:arrayNumbers];
[sortedArray sortUsingSelector:@selector(compare:)];
return(sortedArray);
}
gary