Objective-C: How do you declare and save an int?

Here is my code:

@interface Game : Layer // this is from cocos2d
{
   int maxSprites;
}

@implementation Game
-(void)initVariables
{
  maxSprites = 18;
}

Later, when I print it,

 NSLog(@" maxSprites = %d  ", maxSprites);

I get:

 maxSprites = 2

And operations that require it to be 18 are crashing or not working, as if it were really only 2 now.

How is this possible? =)

APPLE+ SHIFT+ FShows another use of the variable maxSprites.

I looked at other code examples, and often they expose the variable with getter and setter, and they also use @property. Am I missing something? I'm new to Objective-C, so I could just be!

EDIT: hrmph, why did I get -1?

Thanks, I'll try to learn how to make Watchpoint.

Until then, I would like to say that I made APPLE+ SHIFT+ Ffor maxSprites "The Project, Textual, Contains, Ignore Case and only as a result of:

Game.h:     int maxSprites;
Game.m:     maxSprites = 18;
Game.m:     NSLog(@" maxSprites  = %d", maxSprites);
Game.m:     NSLog(@" maxSprites  = %d", maxSprites);
Game.m:     NSLog(@"maxSprites is at %p", &maxSprites);
Game.m:     NSLog(@"maxSprites is at %p", &maxSprites);
Game.m:     NSLog(@" maxSprites  = %d", maxSprites);
Game.m:     NSLog(@" maxSprites  = %d", maxSprites);
Game.m:     NSLog(@"maxSprites is at %p", &maxSprites);
Game.m:     NSLog(@"maxSprites is at %p", &maxSprites);

2nd EDIT:

, . :

Expression: "*(int *) 67379960"
New Value: 2
Old  Value: 18

:

[self checkMatchBarAward:spriteTypeToAdd];

? maxSprites.

EDIT: - , , . , , .

: Objective-C: int

0
2

int, . , .

+6

, initVariables ? 2? , maxSprites? :

NSLog(@"maxSprites is at %p", &maxSprites);

, .

: , "" , , , , Objective-C , . malloc MacOS X "" 0.

0

Source: https://habr.com/ru/post/1726269/


All Articles