Property lists question

Discussion in 'iOS Programming' started by swiftd, Aug 18, 2009.

  1. swiftd macrumors newbie

    Joined:
    Jul 12, 2009
    #1
    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.

    [​IMG]
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. swiftd thread starter macrumors newbie

    Joined:
    Jul 12, 2009
    #3
    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.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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.
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    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.
     
  6. swiftd thread starter macrumors newbie

    Joined:
    Jul 12, 2009
    #6
    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"​
     
  7. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    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.
     
  8. swiftd thread starter macrumors newbie

    Joined:
    Jul 12, 2009
    #8
    Working great now, thanks so much!! I really appreciate the help.
     

Share This Page