This is confusing to me. I have a function that does this:
void ListAllStoredLocations(NSString *SearchTerm){
NSMutableDictionary *item;
NSString* filePath = [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/Preferences/yourprogram.plist"];
item = [[[NSMutableDictionary alloc] initWithContentsOfFile:filePath] mutableCopy];
NSMutableArray *ReadStoredArray = [item objectForKey:SearchTerm];
NSMutableArray *SortedArray = [[NSMutableArray alloc] init];
NSString *CurrentResult=@"";
for (int i = 0; i< [ReadStoredArray count]; i++){
CurrentResult=(NSString *)[ReadStoredArray objectAtIndex:i];
[SortedArray addObject:CurrentResult];
}
[SortedArray sortUsingSelector:@selector(compare:)];
for (int i = 0; i< [SortedArray count]; i++){
NSLog(@"%@",[SortedArray objectAtIndex:i]);
}
[item release];
}
Which finds outputs NSStrings in the first for loop like this:
Location1
Location2
Not a location
Location2
Location3
Location2
and I want the output to be alphabetical:
Location1
Location2
Location2
Location2
Location3
Not a location
But, no matter what, the "[SortedArray sortUsingSelector:@selector(compare:)];" just does not sort the array. Nothing happens.
Maybe I'm going about this all wrong, but every example that I've seen online sorts NSStrings like this - so I don't know what to do.
My endgame, if there is a better solution out there is to output the count of the greatest repeated entry. I was thinking that sorting would be a step in that direction.
Really, what I'm looking for is this as output:
Location2
Because "location2" has the most duplications in that list.
Any help?