No, your implementation is not 100% correct. Think what happens if the firstName is currently set to a NSString-instance and the setter is called with that very same instance. First you will release the instance, than you will set the instance variable, which in this case dosen't change anything and than you try the retain the instance, but by that time it could very well been dealloced already.
It should be:
- (void)setFirstName:(NSString*)firstNameValue {
[self willChangeValueForKey:@"firstName"];
[firstNameValue retain];
[firstName release];
firstName = firstNameValue;
[self didChangeValueForKey:@"firstName"];
}
or:
- (void)setFirstName:(NSString*)firstNameValue {
if (firstNameValue != firstName) {
[self willChangeValueForKey:@"firstName"];
[firstName release];
firstName = firstNameValue;
[firstName retain];
[self didChangeValueForKey:@"firstName"];
}
}
The latter version has the additional advantage of not sending oberserver-notifications if the value is not really changed.