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

swiftd

macrumors newbie
Original poster
Jul 12, 2009
11
0
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.

96326986.jpg
 
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.
 
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.
 
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.
 
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.
 
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"​
 
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.
 
Working great now, thanks so much!! I really appreciate the help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.