Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 7, 2013, 04:02 AM   #1
Mvkoe
macrumors member
 
Join Date: Aug 2008
Location: Belgium
Annotation in Plist

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
Mvkoe is offline   0 Reply With Quote
Old Feb 7, 2013, 04:53 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
No. A dictionary consists of keys and values. You have no key.
robbieduncan is offline   0 Reply With Quote
Old Feb 7, 2013, 08:29 AM   #3
Mvkoe
Thread Starter
macrumors member
 
Join Date: Aug 2008
Location: Belgium
Quote:
Originally Posted by robbieduncan View Post
No. A dictionary consists of keys and values. You have no key.
Could you help me further then ? how i should approach this ?
Mvkoe is offline   0 Reply With Quote
Old Feb 7, 2013, 08:38 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by Mvkoe View Post
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.
robbieduncan is offline   0 Reply With Quote
Old Feb 7, 2013, 10:06 AM   #5
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by Mvkoe View Post
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?
Collections Programming Topics.

Cocoa Core Competencies: Property list.
chown33 is offline   0 Reply With Quote
Old Feb 7, 2013, 04:28 PM   #6
Mvkoe
Thread Starter
macrumors member
 
Join Date: Aug 2008
Location: 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>
Mvkoe is offline   0 Reply With Quote
Old Feb 8, 2013, 03:44 AM   #7
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
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.
robbieduncan is offline   0 Reply With Quote
Old Feb 8, 2013, 05:02 AM   #8
Mvkoe
Thread Starter
macrumors member
 
Join Date: Aug 2008
Location: Belgium
Quote:
Originally Posted by robbieduncan View Post
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
Mvkoe is offline   0 Reply With Quote
Old Feb 8, 2013, 05:04 AM   #9
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by Mvkoe View Post
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
robbieduncan is offline   0 Reply With Quote
Old Feb 8, 2013, 05:12 AM   #10
Mvkoe
Thread Starter
macrumors member
 
Join Date: Aug 2008
Location: Belgium
Quote:
Originally Posted by robbieduncan View Post
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!
Mvkoe is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:25 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC