On Jul 4, 2009, at 11:43 PM, Andrew Farmer wrote:

- (int)numberOfSides {
        return numberOfSides;
}
- (void)setNumberOfSides:(int)value {
                numberOfSides = value;
}
Let me guess: does your stack trace (type "tb" in the gdb console) indicate infinite recursion? Either synthesize accessors or write your own - but don't try to do both at once. Down that road lies madness.

This is not correct.

Certainly there is little point in using @synthesize if you're going to implement both the getter and setter, however it is perfectly reasonable to use @synthesize and still provide a custom implementation of one of the methods. The instruction to the compiler is to synthesize the methods *if it cannot find any other implementation*. <http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW14 >


In the case of the implementations provided here, both of them are valid and will not result in infinite recursion.

If the implementations had been:

- (int)numberOfSides {
        return self.numberOfSides;
}

and/or

- (void)setNumberOfSides:(int)value {
        self.numberOfSides = value;
}

then this would have resulted in infinite recursion.

mmalc

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to