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

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


    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:
    <file name="splash.png" />
    <file name="intro.caf" />

    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

    Aug 29, 2010
    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


    Staff Member

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

Share This Page