Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mvkoe

macrumors regular
Original poster
Aug 4, 2008
103
3
Belgium
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
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Could you help me further then ? how i should approach this ?

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.
 

Mvkoe

macrumors regular
Original poster
Aug 4, 2008
103
3
Belgium
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>
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

Mvkoe

macrumors regular
Original poster
Aug 4, 2008
103
3
Belgium
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.

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
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

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
 

Mvkoe

macrumors regular
Original poster
Aug 4, 2008
103
3
Belgium
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

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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.