I am wondering what is happening behind the scenes here. The code works fine but I was kind of expecting it to add the sorted object to the Array.
I created a Class called BoilerPlateCode which I am putting often used methods in to that I will need to call. I wrote a method that sorts an NSArray and returns NSMutableArray.
I then call it like this
My question is... The last line of code "staticSkills = [bpc sortArray: staticSkills];" takes the Array, sorts it and then returns it to the same Array object. Since I never removed the objects from the array in the first place I would think that it would have an accumulative result with a duplicate set of objects in it since it is a mutableArray?
I created a Class called BoilerPlateCode which I am putting often used methods in to that I will need to call. I wrote a method that sorts an NSArray and returns NSMutableArray.
Code:
-(NSMutableArray*)sortArray: (NSArray*) incomingArray{
NSArray *tempArray = [incomingArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSMutableArray * makeMutableArray = [NSArray arrayWithArray:tempArray];
return makeMutableArray;
}
I then call it like this
Code:
BoilerPlateCode *bpc = [[BoilerPlateCode alloc] init];
staticSkills = [[NSMutableArray alloc] initWithObjects:@"Demon Lore", @"Sword",@"Preception",@"Surgery", @"Tracking",nil];
staticSkills = [bpc sortArray: staticSkills];
My question is... The last line of code "staticSkills = [bpc sortArray: staticSkills];" takes the Array, sorts it and then returns it to the same Array object. Since I never removed the objects from the array in the first place I would think that it would have an accumulative result with a duplicate set of objects in it since it is a mutableArray?