The practical difference that I've found is that the debugger doesn't appear to show you the value of properties, just instance variables.
Therefore, your first example, which (assuming you use the @synthesize
directive to create your getter/setter) automatically creates the ivar, will not have a value that you can easily retrieve during debug. You'll end up having to send a lot of NSLog
messages, rather than just looking at the values while stepping through your code.
As an aside, which seems to relate to this topic, I typically prepend my ivars with "iv" and change my color settings in XCode preferences so that I'm never unsure whether I'm accessing a property or an ivar.
Example
@interface MyClass : NSObject {
NSString *ivName;
NSString *ivTitle;
}
@property (nonatomic, copy) NSString *Name;
@property (nonatomic, copy) NSString *Title;
@end
Now, this then requires a small trick (to tie the two together) when synthesizing the properties, which I show below:
@implementation MyClass
@synthesize Name = ivName;
@synthesize Title = ivTitle;
This way, it's always very easy for me to know exactly what's going on at a glance. Yes, context can also tell you whether you're accessing an ivar/property, but why not make it easier?