PDA

View Full Version : Property lists question




swiftd
Aug 18, 2009, 07:58 AM
I'm trying to work out the best method to store data for my iPhone game. From what I can see, a property list seems like the way to go, but have a quick question as to their use.

Regarding the following pic (from the Property List Programming Guide), is it possible to have a setup like this but be able to have a defined string instead of 'Item 1' and 'Item 2'? If so, how? I tried to do it using sub-arrays but couldn't get it working. Any help would be greatly appreciated! Cheers.

http://img32.imageshack.us/img32/4069/96326986.jpg



robbieduncan
Aug 18, 2009, 08:02 AM
Not in an Array: they are indexed by number (those labels don't actually exist in the file). If you use a Dictionary then yes, you can have key/value pairs.

swiftd
Aug 19, 2009, 08:22 AM
Not in an Array: they are indexed by number (those labels don't actually exist in the file). If you use a Dictionary then yes, you can have key/value pairs.

Thanks for your reply. How can I get items to belong to another item in the property list? This is basically the data setup I'm imagining:

Character 1
-> Stats
-> Attack: 88
-> Defense: 97
-> Image paths
-> Normal: normal.jpg
-> Dead: dead.jpg


Is this possible in a property list? Thanks again.

robbieduncan
Aug 19, 2009, 08:23 AM
Depends on the type of the object. So if the root object is an Array then you get an NSArray object that you can itterate through, if it's a Dictionary you get an NSDictionary. The documentation tells you all you need to know.

PhoneyDeveloper
Aug 19, 2009, 11:32 AM
Typically you model an 'item' that has properties with a dictionary. So a row in a table is a dictionary. It can have title, subtitle, icon, checkmark, etc properties. Each of the properties is a key/value pair.

"title" "this is the first title"
"icon" "path/to/icon27.png"

etc.

If you have a bunch of 'items' then you have an array of dictionaries.

Your description seems like you want an array of dictionaries. Each dictionary represents a character and its properties.

"Attack" 88
"Defense" 97
"Normal" "normal.jpg"
"Dead" "dead.jpg"

For numbers you can use NSNumbers or NSStrings.

swiftd
Aug 20, 2009, 03:45 AM
Typically you model an 'item' that has properties with a dictionary. So a row in a table is a dictionary. It can have title, subtitle, icon, checkmark, etc properties. Each of the properties is a key/value pair.

"title" "this is the first title"
"icon" "path/to/icon27.png"

etc.

If you have a bunch of 'items' then you have an array of dictionaries.

Your description seems like you want an array of dictionaries. Each dictionary represents a character and its properties.

"Attack" 88
"Defense" 97
"Normal" "normal.jpg"
"Dead" "dead.jpg"

For numbers you can use NSNumbers or NSStrings.

Thanks for your reply. I think I understand that part, but can I use the one property list to store that type of data for numerous characters? i.e.

Character 1
"Attack" 88
"Defense" 97
"Normal" "normal.jpg"
"Dead" "dead.jpg"
Character 2
"Attack" 95
"Defense" 82
"Normal" "normal.jpg"
"Dead" "dead.jpg"

robbieduncan
Aug 20, 2009, 04:40 AM
Thanks for your reply. I think I understand that part, but can I use the one property list to store that type of data for numerous characters? i.e.

Character 1
"Attack" 88
"Defense" 97
"Normal" "normal.jpg"
"Dead" "dead.jpg"
Character 2
"Attack" 95
"Defense" 82
"Normal" "normal.jpg"
"Dead" "dead.jpg"

Yes: set the base element as an array, set each character as a dictionary and include the characters "name" as key/value pair in the dictionary.

swiftd
Aug 20, 2009, 08:06 AM
Working great now, thanks so much!! I really appreciate the help.