views:

176

answers:

3

Hi,

This site is great I'm getting alot of replies , so I have tried to code what I had problems with before here it is

NSMutableArray *sort = [NSMutableArray arraywithArray:[dic allValues]]; 

for(NSString *s in sort){
    [Purchases appendString:[NSString stringWithFormat:@"%@",s]]; 
} 
textview.text = Purchases; 

The output's order still does not appear like it does when i Open the Plist file... Also a side note is it possible to write and open plist files in your Resources folder instead...

Thanks for the help!

Edit:

2010-02-12 23:54:35 -0500 
2010-02-12 23:29:11 - 0500 
2010-02-12 23:54:42 - 0500 
2010-02-12 23:54:58 - 0500  

thats the Order I get ^^

but when I open the plist file the order is:

2010-02-12 23:29:11 -0500 
2010-02-12 23:54:35 -0500 
2010 02-12 23:54:42 - 0500 
2010 02-12 23:54:58 - 0500 

^^ Thats the order I want except in descending

+3  A: 

[dic allValues] does not return keys in any sort of reliable order. It's using a set underneath, which means it's unordered.

If you're looking for a dictionary that also maintains insertion order, check out CHOrderedDictionary that's part of the CHDataStructures framework.

Dave DeLong
+1  A: 

I would like to show it in descending order (latest date time first)...

Then you need to sort it. You cannot count on a dictionary giving you its contents in any order, not even the order you loaded or inserted them in.

Peter Hosey
+2  A: 

As specified in the documentation, the order of the values is not specified. So you need to sort the keys before the iteration, with one of the sort methods of NSArray.

For example, this code will sort the string values in the ascending order:

NSArray *sort = [[dic allValues] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

for(NSString *s in sort){
    [Purchases appendString:[NSString stringWithFormat:@"%@",s]]; 
} 
textview.text = Purchases; 

Refer to the NSArray documentation to learn about the various way on sorting an array (selector, blocks, etc).

Laurent Etiemble