iphone - Best way to store class variables? -


I am making a very simple game, but I can not determine what my custom class will use. I just know two ways of doing this, but think about the rules of other people where you kept some things. I would like to know how I should use the variable, I am using it efficiently, and I expected that I can find answers here.

Actually, this is my header file.

  # Import & lt; Foundation / Foundation. H & gt; #import "URWInventoryView.h" @ Interface RWInventory: NSObject {URWInventoryView * inventoryWindow; Bull slot is encapsulated [5] [5]; Int numbersoffices; Int number offslotfil; Int number of columns; Int numberoffro; } // ///// //// Initial //// // - (ID) initWithSlots: (int) slots; - (id) initWithColumns: (int) column and row: (integer) rows; - (ID) initWithInventoryData: (RWInventory *) list; // //// ////Seters//// // - (zero) set slot: (int) slots; - (zero) set column: (int) column; - (zero) setrise: (integer) rows; - (zero) setSlotIsOccupiedColumn: (int) column and row: (int) line; - (zero) moveItemAtColumn: (int) column and row: (int) row to column: (int) newColumn and row: (int) newRow; // ////////Getter//// // - (Int) slot; - (int) column; - (integer) rows; - (BOOL) slotIsOccupiedColumn: (int) column and row: (int) line; @And   

This first method uses what I was talking about earlier. The second method involves using a single NSDictionary between the #import and the @interface declaration, and they assign the data of each object to a key . The above method seems very easy and efficient for me.

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

This is not entirely clear, but I will take a shot at it. I am sorry if I am not here in the right ballark. What I am able to parse with the question, your question basically sprouts in two options:

  1. Global Dictionary : The Global Dictionary contains all the items kept for each Store an inventory view (example 5 - 20) or ...
  2. See an example of viewing the data : For each instance of an inventory view, an inventory is a data object.

    As long as there is no reason that you need global access, then I would recommend using visualization data per view. I always start with data that requires data, which is needed locally and then returns to create global data if necessary. If the data needs to be shared between scenes, then I will make a model and consider the singleton pattern to access the model (Inventory Mode * Invo = [Inventory Model Sharing Instance]). Search for Singleton Objective-C

    But once again, unless there is a requirement, I will localize the data on the data that is running on the data. Global and shared data can always complicate the lifetime of the data and possibly synchronization.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -