Annotation in Plist

Discussion in 'iOS Programming' started by Mvkoe, Feb 7, 2013.

  1. Mvkoe macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #1
    Hey!

    I'm making a map application with annotations, and but i'm a bit confused when using plists and then choosing between dictionaries and arrays in a plist. I'm not sure when I need to use a dict and then array?

    I would have a sorted list from A to Z. and in the A to Z comes my Annotations with name, and then within the name an Description, subtitle, picture, title, aso.

    So i would try someting like this ?

    Code:
    <dict>
    - <array>(for the A to Z)
    -- ??? 
    - </array>
    </dict>
    Could somebody help me out of this ?

    Grz
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    No. A dictionary consists of keys and values. You have no key.
     
  3. Mvkoe thread starter macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #3
    Could you help me further then ? how i should approach this ?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    If you want an array use an array. If you want a key/value pair set use a dictionary. You say you want an array representing A-Z and then some sort of dictionary structure for each element. So you would have an array containing 26 dictionaries.
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
  6. Mvkoe thread starter macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #6
    Oke i have someting like this now!

    Would this be the right way?

    Code:
    <dict>
    	<key>A</key>
    	<array>
    		<dict>
    			<key>description</key>
    			<string>Bla</string>
    			<key>lat</key>
    			<string></string>
    			<key>long</key>
    			<string></string>
    			<key>picture</key>
    			<string></string>
    			<key>subtitle</key>
    			<string></string>
    			<key>title</key>
    			<string>First Annotation</string>
    		</dict>
    	</array>
    	<key>B</key>
    	<array/>
    	<key>C</key>
    	<array/>
    	<key>D</key>
    	<array/>
    	<key>E</key>
    	<array/>
    	<key>F</key>
    	<array/>
    	<key>G</key>
    	<array/>
    	<key>H</key>
    	<array/>
    	<key>I</key>
    	<array/>
    	<key>J</key>
    	<array/>
    	<key>K</key>
    	<array/>
    	<key>L</key>
    	<array/>
    	<key>M</key>
    	<array/>
    	<key>N</key>
    	<array/>
    	<key>O</key>
    	<array/>
    	<key>P</key>
    	<array/>
    	<key>Q</key>
    	<array/>
    	<key>R</key>
    	<array/>
    	<key>S</key>
    	<array/>
    	<key>T</key>
    	<array/>
    	<key>U</key>
    	<array/>
    	<key>V</key>
    	<array/>
    	<key>W</key>
    	<array/>
    	<key>X</key>
    	<array/>
    	<key>Y</key>
    	<array/>
    	<key>Z</key>
    	<array/>
    </dict>
    
     
  7. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    It's a way. This will not give you an array representing A-Z, rather a dictionary indexes A-Z. This may or may not be better, depends in your usage.
     
  8. Mvkoe thread starter macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #8
    I've made my alfabet array like this:

    Code:
    self.alfabet = [[AnnotationsData allKeys] sortedArrayUsingSelector:@selector(compare:)];
    So when i do NSLog, i have an array of A-Z
     
  9. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #9
    Which is fine, although potentially unnecessary. You could just do:

    Code:
    <array>
     <!-- A -->
     <array>
      <dict>...</dict>
      ....
     </array>
     ...
     <!-- Z -->
     <array>
      <dict>...</dict>
     </array>
    </array>
    
    which would just load as an array of arrays. As I said: it depends on your desired usage as to which structure makes most sense. There is no right or wrong and only you can decide which is best/easiest for your app
     
  10. Mvkoe thread starter macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #10
    Okay! Thanks for the heads up! I'll try using mine first, and if that doesn't do what I want or it gets a mess, I'll use your way!
     

Share This Page