tags:

views:

25

answers:

1

I was just working through a iPhone book and I noticed a comment that stated...

If you declare a property with a different name than its underlying instance varaible (which can be done with the @synthesize directive)

Can anyone explain how the above quote might work, I am just curious as all references to @property / @synthesize always look like my code below.

@interface Planet : NSObject {
    NSString *planetName;
}

@property(copy) NSString *planetName;
...
@synthesize planetName;

gary

+2  A: 

I would presume the book would go on to explain, but i would look like this:

@interface Planet : NSObject {
    NSString *name;
}

@property(copy) NSString *planetName;
...
@synthesize planetName = name;
Chuck
Hi Chuck, no such luck thats all it gave. Thank you for the answer, I was not aware that you could do that. I guess its not mentioned much as it does look a little clunky and potentially hard to read. Thanks again ...
fuzzygoat
Well, mainly it's just unnecessary because you usually have the option of naming the property the same as the ivar. So most people just do that for simplicity's sake. This is primarily useful if you use some sort of Hungarian notation for your variables.
Chuck