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

  • Home
  • SEARCH
  • 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 6543423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:20:42+00:00 2026-05-25T11:20:42+00:00

I am making a very simple game, but I cannot decide on how to

  • 0

I am making a very simple game, but I cannot decide on how to store the variables my custom classes will use. I only know of two ways to do this, but other people seem to have rules about where you put certain things. I would like to know how I should store the variables I am using efficiently, and I was hoping I could get the answer here.

Basically, this is my header file.

#import <Foundation/Foundation.h>
#import "URWInventoryView.h"

@interface RWInventory : NSObject {
    URWInventoryView *inventoryWindow;

    BOOL slotIsOccupied[5][5];

    int numberOfSlots;
    int numberOfSlotsFilled;
    int numberOfColumns;
    int numberOfRows;
}

//
////
//// Initializers
////
//

- (id) initWithSlots:(int)slots;
- (id) initWithColumns:(int)columns andRows:(int)rows;
- (id) initWithInventoryData:(RWInventory*)inventory;

//
////
//// Setters
////
//

- (void) setSlots:(int)slots;
- (void) setColumns:(int)columns;
- (void) setRows:(int)rows;

- (void) setSlotIsOccupiedColumn:(int)column andRow:(int) row;
- (void) moveItemAtColumn:(int)column andRow:(int)row toColumn:(int)newColumn andRow:(int)newRow;

//
////
//// Getters
////
//

- (int) slots;
- (int) columns;
- (int) rows;

- (BOOL) slotIsOccupiedColumn:(int)column andRow:(int)row;

@end

That uses the first method I was kinda talking about earlier. The second method involves using a single NSDictionary between the #import‘s and the @interface declaration, and they simply store each object’s data in a key. The method used above sounds much easier and efficient to me.

Please keep in mind that I will be using anywhere between five and twenty objects of this type. My last note: URWInventoryView is another one of my custom classes, and it is based on a UIView.

  • 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-25T11:20:42+00:00Added an answer on May 25, 2026 at 11:20 am

    It’s not completely clear but I’ll take a shot at it. Forgive me if I’m not in the right ballpark here. From what I was able to parse from the question, your question basically boils down to two options:

    1. Global Dictionary: the global dictionary stores all the inventory keyed for each instance of inventory view (5 – 20 instances) or…
    2. Data Scoped to Instance of View: for each instance of the inventory view, have an inventory data object.

    Unless there’s a reason why you need global access I would recommend using instance data per view. I would always start with data being localized to the data that needs it and then fall back to making global data if required. If data did need to be shared between views I would create a model and consider a singleton pattern to get access to the model (InventoryModel *inv = [InventoryModel sharedInstance]). Search for singleton objective-c.

    But once again, unless there’s a need, I would localize the data to the view that operates on that data. Global and shared data can always complicate lifetime of the data and possibly synchronization.

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

Sidebar

Related Questions

I was making this very simple lex program (just an introductory program). But on
I'm making simple game with very simple thread (1 sec delay) got problem with
I'm making a very simple html webpage consisting only of text. How can I
Very simple problem but I'm making no progress so I thought I should ask...
I'm making a very simple game application. The main form (Form1) has a single
Just making a very very simple order form. Want a input box ( only
I'm making a very simple turn based battle game using ActionScript 2.0. I'm VERY
I'm making a very simple fishing game. the user has to buy pots, easy
I am making a very simple blog for my PHP project, but am having
I'm making a simple RTS game. I want it to run very fast because

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.