For example, I have a UIViewController, and have a value:
NSString *testString;
@property (nonatomic, retain) NSString *testString;
in the .m:
@synthesize testString;
And what is the different between these two lines of code:
testString = @"something";
self.testString = @"something";
The first case assigns new value to
testString, you are accessingtestStringdirectly:In the second case:
You are calling
settergenerated by calling@synthesize testStringand the fact that it’s a property.The second case calls generated
[aUIViewControllerObject setTestString: @"something"]in which the@"something"NSStringis retained (because thetestStringproperty is declared withretainparameter), the old value isautoreleasedorreleasedand the new value is assigned totestString.