You don't have to provide an instance variable. You need some place to store the value (unless it is dynamic) so there is usually an instance variable for every property.
In your second example, where would you actually store the name?
If you don't have an instance variable for the property you can't use the synthesized setter/getter and have to write your own. You still have to have a place to store the value or have some way of saving and retrieving it (ie: NSUserDefaults, a file, ...).
Here is the code @synthesize name;
generates for you and you can see it uses the name instance variable:
-(void)setName:(NSString*)newName {
[newName retain];
[name release];
name = newName;
}
-(NSString*)name {
return [[name retain] autorelease];
}
With your second example, without the instance variable, we could implement like this:
@implementation MyObject
@dynamic name;
-(void)setName:(NSString*)newName {
[[NSUserDefaults standardUserDefaults] setObject:newName forKey:@"name_key"];
}
-(NSString*)name {
return [[NSUserDefaults standardUserDefaults] stringForKey:@"name_key"];
}