Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3933720
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:37:59+00:00 2026-05-19T23:37:59+00:00

I am writing an iPhone game and have it working well with my level

  • 0

I am writing an iPhone game and have it working well with my level data hard coded but I would like to store the level data in a plist a load it at launch. I have never used plists and am having trouble understanding how I should set the plist up based on my data model.

Here is how I have it hard coded now:

(in my appDelegate)

- (void)loadLevels {
    //setup NSNumber objects to load into sequences
    NSNumber * rID = [[[NSNumber alloc] initWithInt:0] autorelease];
    NSNumber * bID = [[[NSNumber alloc] initWithInt:1] autorelease];
    NSNumber * gID = [[[NSNumber alloc] initWithInt:2] autorelease];
    NSNumber * yID = [[[NSNumber alloc] initWithInt:3] autorelease];
    NSNumber * rbID = [[[NSNumber alloc] initWithInt:4] autorelease];
    NSNumber * rgID = [[[NSNumber alloc] initWithInt:5] autorelease];
    NSNumber * ryID = [[[NSNumber alloc] initWithInt:6] autorelease];
    NSNumber * bgID = [[[NSNumber alloc] initWithInt:7] autorelease];
    NSNumber * byID = [[[NSNumber alloc] initWithInt:8] autorelease];
    NSNumber * gyID = [[[NSNumber alloc] initWithInt:9] autorelease];

    //Level One's Sequence
    NSMutableArray * aSequence = [[[NSMutableArray alloc] initWithCapacity:1] autorelease];

    [aSequence addObject: rID];
    [aSequence addObject: bID];
    [aSequence addObject: gID];
    [aSequence addObject: yID];
    [aSequence addObject: rbID];
    [aSequence addObject: rgID];
    [aSequence addObject: ryID];
    [aSequence addObject: bgID];
    [aSequence addObject: byID];
    [aSequence addObject: gyID];

    // Load level One
    _levels = [[[NSMutableArray alloc] init] autorelease];

    Level *level1 = [[[Level alloc] initWithLevelNum:1 levelSpeed:1.0 levelSequence:aSequence] autorelease];

    [_levels addObject:level1];
 //do the same thing for subsequent levels//
}

(this is how I have my Level Class implemented)

#import "Level.h"

@implementation Level

@synthesize levelNum = _levelNum;
@synthesize levelSpeed = _levelSpeed;
@synthesize levelSequence = _levelSequence;

- (id)initWithLevelNum:(int)levelNum levelSpeed:(float)levelSpeed levelSequence:(NSMutableArray *)levelSequence {
    if ((self = [super init])) {
        self.levelNum = levelNum;
        self.levelSpeed = levelSpeed;
        self.levelSequence = [[[NSMutableArray alloc] initWithArray:levelSequence] autorelease];
    }
    return self;
}

- (void)dealloc {
    [_levelSequence release];
    _levelSequence = nil;
    [super dealloc];
}

@end

I’m just not getting how to set up a plist to store my data to match my model. Can anyone give me some advise please?

ADDITION:
(here is how I think I need to setup the plist – the data model is simply the three variables initializing my level (above). If you look at my current plist it might be more clear how it is setup, but each level is comprised of: a level number, a level speed, and an array of numbers denoting the required sequence for that level.)

My current plist setup

Now, if I do have this setup correctly how do I load the values into my program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:38:00+00:00Added an answer on May 19, 2026 at 11:38 pm
    • Add your plist file as a resource file in your project. Say, it’s name is config.plist

    • Get the path for the resource file. (Though, be careful of [NSBundle mainBundle] as it will not return the unit test bundle in a unit test.)

    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    
    • Your root object is an array of levels. Load it in a NSArray.
    // this is autoreleased. you can retain it if needed
    NSArray *levelArray = [NSArray arrayWithContentsOfFile:plistPath];
    
    • Now you have the array of levels. Each level is a dictionary. Load the level i (counting from 0).
    NSDictionary *level = [levelArray objectAtIndex:i];
    
    • Now you can get the objects from level dictionary by using objectForKey method. For example, to get the sequence array:
    NSArray *seq = [level objectForKey:@"levelSequence"];
    
    • You can loop through the levelArray to alloc, init and add to levels array for all your levels.

    Hope it helps. Please note that I have not compiled the code, so there might be some typos.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an iPhone game in objective-C using XCode. I'd like to profile the
I am writing a game for the iPhone/iPodTouch (using Cocos2d) and I have noticed
I'm building a client/server iPhone game, where I would like to keep third-party clients
I am writing an iphone game using cocos2d and box2d engines. I have a
I'm writing a game using cocos2d-iphone and our stages are defined in .plist files.
I'm writing a game for iPhone, and I want an online leaderboard using mySQL,
I'm writing a retro type game for the iPhone, and need to render a
I'm writing an iPhone App that relies on getting the device location. Management have
I'm writing an iPhone app for a client, and they have requested a feature
Am a flash game developer at present I started writing games for iphone using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.