How to load and cache resources files mentioned in xml / plist when app start?

Discussion in 'iOS Programming' started by webphone, Nov 10, 2010.

  1. webphone macrumors newbie

    Joined:
    Jan 18, 2010
    #1
    There is a Resources folder which I store png images and sound files

    e.g.
    Resources/images/splash.png
    Resources/sound/intro.caf

    I want to store the path and file names in a xml or plist file.

    So that it can be configured easily when development.

    The XML schema:
    <resources>
    <images>
    <file name="splash.png" />
    </images>
    <sound>
    <file name="intro.caf" />
    </sound>
    </resources>

    I am not sure how to create the plist to store those values.

    I saw a code in a project but it seems to load the plist file:

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:mad:"Splash.plist"];

    My question is how is the objective-c code to load and cache resources files mentioned in xml / plist when app start?
     
  2. cnstoll macrumors 6502

    Joined:
    Aug 29, 2010
    #2
    You want two things:

    1) When your app loads you want to read the plist file into an NSData object,

    2) and then convert that into a NSDictionary to read your data from.

    Look at the NSData, NSFileManager, and NSDictionary documentation, it should have what you need. Specifically look at the NSFileManager "contentsAtPath:UIPath" method which returns an NSData object, and the NSData method "propertyListFromData:NSData" method which returns a dictionary.

    You can call that initialization stuff from basically anywhere you want, and just initialize your variables from the data in the dictionary.

    Hope that helps.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    You could also consider just using NSData's dataWithContentsOfFile: class method.
     

Share This Page