0

I have been synthesizing objects in my .m file this way:

@synthesize myObject;

And if I have many objects, I do it like this:

@synthesize myObject1, myObject2, myObject3;

However I see some people synthesize this way:

@synthesize myObject = _myObject;

Can somebody explain which is better way to synthesize the object?

GeneCode
  • 7,545
  • 8
  • 50
  • 85

2 Answers2

0

Like this : Ans 1 :

- (void)setCoolWord:(NSString *) myObject {
          _myObject = myObject;
    }

- (NSString *) myObject {
    return _myObject;
}

Hope it helped.

with Xcode 4.5 or up. The IDE write the @synthesize statement for you.

The @synthesize statement is only write the setter and getter for you.

that, _variable_name is the instant variable.

The variable_name is only a method that returns the value of _variable_name by default.

when using the variable = <Statement or value>. its calling thesetVarable_Namemethod to set the_variable_name` by default.
Monika Patel
  • 2,287
  • 3
  • 20
  • 45
0
  1. in .h like this,

2.@property (nonatomic, strong) NSString *fullName;

3.do in .m where you want there written like this by using self or (_).

  1. self.fullName (or) _fullName ;