cocos2d iphone - What's the difference between declaration of an int with int keyword or with @property (nonatomic, assign)? -


i want know difference between writing :

@interface monster : ccsprite  @property (nonatomic, assign) nsstring *life; @property (nonatomic, assign) int color;  - (id)initwithfile:(nsstring *)file hp:(int)life:(nsstring *)color;  @end 

and :

@interface monster : ccsprite{     nsstring *life;     int color; } - (id)initwithfile:(nsstring *)file hp:(int)life:(nsstring *)color;  @end 

thank in advance help.

short answer: when add property, class invoked can have access it. example

levelclass alloc , init monster class , has access property this

monster *monsteristance = [[monster alloc] init]; nslog(@" monster life = %@", monsteristance.life); 

and once use @property @synthesize automatically generates set , get code.

self.life = @"text"; 

is equal to

[self setlife: @"text"]; 

long answer: check out when-to-use-properties-in-objective-c , why-would-you-use-an-ivar

and should read this tutorial ray wenderlich site explain lot arc / property etc


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -