Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping through an dictionary; why do I not get the keys alphabetically?
    primarykey
    data
    text
    <p>I am writing an iPhone app using S7Graphview and I have saved some dates and results to a .plist as keys and values in a dictionary, both as strings. My plist looks like this:</p> <pre><code>&lt;dict&gt; &lt;key&gt;2011-05-11&lt;/key&gt; &lt;string&gt;23&lt;/string&gt; &lt;key&gt;2011-05-12&lt;/key&gt; &lt;string&gt;23&lt;/string&gt; &lt;key&gt;2011-05-13&lt;/key&gt; &lt;string&gt;23&lt;/string&gt; &lt;key&gt;2011-05-14&lt;/key&gt; &lt;string&gt;43&lt;/string&gt; &lt;key&gt;2011-06-14&lt;/key&gt; &lt;string&gt;43&lt;/string&gt; &lt;/dict&gt; </code></pre> <p>Then I use this loop to load those values into the graphview:</p> <pre><code>NSMutableDictionary* dictionary = [[NSMutableDictionary alloc]init]; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath]; int i = 1; if ([dictionary count] &gt; 0) { for (NSString* key in dictionary){ NSString* verdiString = [dictionary objectForKey:key]; CGFloat verdi = [verdiString intValue]; NSDate *dato = [[NSDate alloc]init]; NSLog(@"key=%@ value=%@", key, [dictionary objectForKey:key]); dato = [self stringTilDato:key]; [items.list_ addObject:[[GraphInfo alloc] initWithID:i name:verdiString value:verdi date:dato]]; i++; } } </code></pre> <p>The "stringTilDato" method converts the date string to a NSDate. The values get loaded into the items.list, but in the wrong order! The NSLog reports:</p> <pre><code>key=2011-05-14 value=43 key=2011-05-13 value=23 key=2011-05-12 value=23 key=2011-06-14 value=43 key=2011-05-11 value=23 key=2011-05-14 value=43 key=2011-05-13 value=23 key=2011-05-12 value=23 key=2011-06-14 value=43 key=2011-05-11 value=23 </code></pre> <p>(Don't know why it goes through the keys twice, btw, but I dont't believe that's important). I thought the keys would be read alphabetically, or at least in the order of the plist. Why does the plist get loaded into the dictionary in this order, or is it my loading loop that is the problem?</p> <p>Hope there is someone out there who can help me :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload