I made a getter do this:
@synthesize sheet = _sheet;
-(CCSpriteBatchNode *)sheet {
if (!_sheet) {
_sheet = [CCSpriteBatchNode batchNodeWithFile:@"image.png" capacity:500];
[self addChild:_sheet];
}
return _sheet;
}
But my question is, what is the proper way to declare this property?
in my interface, I have done:
@property (readonly, unsafe_unretained) CCSpriteBatchNode *sheet;
because I thought, since this is “readonly”, I don’t need a strong reference to it– but then I got confused and thought– wait does that mean there’s a chance it will get released, and this should be strong? I used unsafe_unretained instead of weak to have iOS4 support…
“readonly” property means that there is no setter function to modify the value of the property. That has nothing to do with “strong” versus “weak/unsafe_unretained”.
You should declare the property “strong” to make sure that the object is not released while somebody is using it.
In your particular case,
selfprobably retains_sheetbecause of[self addChild:_sheet], so_sheetwill exist at least as long asself. But if you declare the property as “unsafe_unretained” and another class gets the value viathen
theSheetwill be an invalid pointer as soon asyourWhatEveris deallocated.