I am just looking at sorting NSArrayof NSNumbersin numerical order, but I'm a little unsure of how best to go. In my way of thinking, 001 and 002 are quite comparable, so I would suspect that either he would. For 003, I'm not sure if returning NSMutableArraywhen the method expects NSArrayis good practice, it works, but it feels awkward.
-(NSArray *)testMethod:(NSArray *)arrayNumbers {
NSMutableArray *sortedArray = [NSMutableArray arrayWithArray:arrayNumbers];
[sortedArray sortUsingSelector:@selector(compare:)];
arrayNumbers = [NSArray arrayWithArray:sortedArray];
return(arrayNumbers);
}
.
-(NSArray *)testMethod:(NSArray *)arrayNumbers {
NSMutableArray *sortedArray = [NSMutableArray arrayWithArray:arrayNumbers];
[sortedArray sortUsingSelector:@selector(compare:)];
arrayNumbers = [[sortedArray copy] autorelease];
return(arrayNumbers);
}
.
-(NSArray *)testMethod:(NSArray *)arrayNumbers {
NSMutableArray *sortedArray = [NSMutableArray arrayWithArray:arrayNumbers];
[sortedArray sortUsingSelector:@selector(compare:)];
return(sortedArray);
}
source
share