Question

I am writing class in Objective c.

and I want a private property from type double in my main view controller.

my code: MainViewController.m

#import "MainViewController.h"

@interface MainViewController ()

@property (nonatomic) BOOL x;

@end

@implementation MainViewController

now , i know taht Automatic Property Synthesis With Xcode 4.4 but if i dont write @synthesize x; i can access to my property "x" only with "self.x" or "_x"

and if i write @synthesize x

i can access with just write "x".

i know it is a simple question ,but I really want to understand what is happening in the code behind, and the essential difference between the two approaches.

thanks

Was it helpful?

Solution

If you write @synthesize x; you can either use self.x or x

If you don't synthesize the property the compiler does behind the scenes this: @synthesize x = _x. Now you can either use self.x or _x

But you can synthesize and assign the ivar a different name as well, e.g. @sythesize x = _aBoolen —now you can use self.x or _aBoolean

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top