Question: Different Ways To Declare Objective C Instance Variables

Question

Different Ways To Declare Objective C Instance Variables

Answers 0
Added at 2016-12-31 00:12
Tags
Question

To me, it seems that there are quite a few ways to declare instance variables using Objective C and I'm not sure what is the standard way(s) I should approach this. What are the differences between the following?

I saw this in the new SpriteKit templates:

@implementation GameScene { //instance variables? private?
    SKShapeNode *_spinnyNode;
    SKLabelNode *_label;
}

- (void)didMoveToView:(SKView *)view {
    // Setup your scene here

...

This is what I currently use:

@interface GameScene()

@property SKShapeNode *spinnyNode;

@end

@implementation GameScene

- (void)didMoveToView:(SKView *)view {
    // Setup your scene here

I've also seen the use of @synthesize in certain online examples. I come from more of a Java background where it seems so much more clear. What are the differences?

Answers
Source Show
◀ Wstecz