@interface RandomObject : NSObject
{
NSString* someObject; // I know I don't have to explicitly declare. Just to clarify my point.
}
@property (nonatomic, strong) NSString *someObject;
@end
@implementation RandomObject
@synthesize someObject;
@end
Given the code above and Xcode 4.3 is used (hence, no auto-synthesizing), here is my question.
The property/synthesize will create accessors for someObject, namely getter and setter. So if I want to assign a value to someObject, I can do this.
self.someObject = @"Tomato"; // [self setSomeObject: @"Tomato"];
If my understanding is correct, self will send @"Tomato" to setSomeObject method. But what if you do this?
someObject = @"Tomato"; // or maybe _someObject = @"Tomato" if you are doing auto-synthesizing
Directly accessing an iVar object seems like a bad idea, but since someObject is a private variable, within the same class you have access to that, right?
I understand why you would need to use self.someOject if you want to manipulate someObject from another class. But why is it that you'd need to do the same even though you are still in the same class. Why is it that it's a bad idea to directly access iVar.