Hey Byron.
Sure I'll take a crack at it.. :)
In XCode, it is convention to use the name of the ivar as the method
name. This is perhaps why it looks weird.
You're just returning the ivar 'name' using a method that happens to
be named the same as the ivar. This allows for other
cool tricks like Key-Value Coding and Key-Value Observing. Examples:
[myObject name]
myObject.name
Using this convention, it's very clear which ivar you are asking for.
As for the setter methods, the one you are showing is the Copy setter
(e.g. @property (copy) name; )
The reason for checking first is if by some strange twist of fate, the
parameter is the same as the ivar.
WIthout that 'if' statement above, assuming value == name means when
you release name, value is nil. Then you assign nil to your ivar.
Probably not what you wanted.
As for your array question, it's easiest (and recommended for the
iPhone by Apple) to specify the array as a property with attributes
(nonatomic, retain), and then synthesize it in your implementation:
Atomicity has to do with how the ivars are handled in a multi-threaded
environment. By specifying 'nonatomic', you are simply returning the
value and not using locks during the operation.
By specifying 'retain', you are telling the compiler to create the
setter method for you using a "release-retain" model, something like
this:
- (void) setMyArray: (NSArray *) newMyArray {
if (myArray != newMyArray) {
[myArray release];
myArray = [newMyArray retain];
}
}
The default attribute for @property is (atomic, assign), which makes a
direct assignment
Also there is the (copy) attribute, which does like your code showed,
copies the parameter to your ivar.
Hope that helps.
More info on this in Apple's "The Objective-C Programming Language"
and "Memory Management Programming Guide".
@Mike