I have an NSMutableDictionary of websites
[dictionaryOfSites setObject:@"http://www.example.com" forKey:@"Example.com"];
[dictionaryOfSites setObject:@"http://www.site1.com" forKey:@"Site1"];
[dictionaryOfSites setObject:@"http://www.apple.com" forKey:@"Apple"];
I know you can't sort a dictionary. But I've read that other people have used an NSMutableArray as the key and the array can be sorted.
So if I setup a new array
[[arrayKey alloc] initWithObjects:@"Example.com", @"Site1", @"Apple", nil];
I would then modify my first snippet to
[dictionaryOfSites setObject:@"http://www.example.com" forKey:[arrayForKey objectAtIndex:0]];
[dictionaryOfSites setObject:@"http://www.site1.com" forKey:[arrayForKey objectAtIndex:1]];
[dictionaryOfSites setObject:@"http://www.apple.com" forKey:[arrayForKey objectAtIndex:2]];
In this simple problem, I had 3 sites so I "hard" coded it. How would I do the same thing if my list of sites was 100? How would the order of the sites be maintained?
If I sort my array [arrayKey sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
Wouldn't index 2 become index 0? If it becomes index 0 then you can see the dictionaryOfSites has the wrong label with the URL.