objective c - Array of Objects -


complete and purpose-complete and complete the entire Mac platform, please do not call me =). Actually I'm trying to make a simple game. There is a board in the game for which I have created a class and sections are included in a board, for which I have also created a square (board and square respectively).

In my visual controller, I am trying to instantiate a board and add the board ^ 2 to the object in the class. The board includes an NSMutableArray * class.

I have also created a facility method which sets an NSNumber * sized set that is called initWithDimension.

I have handlers in my spare:

board * Game_board = [[Board allocation] Initvith Demonition: 10]; Int size = [game_board.boardSize intValue]; For (int i = 0; i

... and I'm getting 10 (expected) and then (empty) This is obviously obvious for an experienced developer, I've struggled for an hour now And it's left. I tried it without [release], the same result I also imported square.h and board.h.

Any ideas which are wrong here?

thanks

  1. Here's what you are facing: The code you posted, you never give an object reference to game_board.squares , so it is contained in zero . When you call addObject: , then nothing happens. This objective defines the behavior within the language. Therefore, before you add the object An assignment of sections [[NSMutableArray alloc] initWithCapacity: boardSize * boardSize]] should be added.

  2. You should initiate your board within the initWithDimensions: method to begin this is the whole issue of creating a square - containing the object behavior as the Board is a manager of class objects, it must start and manage.

  3. Stylisticly class names are preferably pascal-sealed, meaning that each word is upper-case: MyClassName . (In this case, like board to board and class to class .)


Comments