Consider the following code:
// MyClass.h
@interface MyClass
@property NSInteger Value;
@end
//MyClass.m
@implementation MyClass
@synthesize Value;
@end
What are the minimal code modifications that I’d need to make if I wanted to override only the synthesized setter method for Value?
As a follow-up, what are the minimal modifications that I’d have to make in order to override only the synthesized getter method?
EDIT
Overriding is simple. (See answers below.) In my case, I was getting a nasty warning because I hadn’t included the nonatomic attribute with my property definitions. Adding the attribute has solved my initial problem resulting in this question.
Apparently it’s not possible to override just one or the other for an atomic property. You must change it to have the
nonatomicattribute.I didn’t know that five minutes ago, and it’s not noted anywhere in TOCPL as far as I can see.
Also change the name to be lower-case. Convention in ObjC is for lower initial letters for ivars.
Beyond that, just implement whichever you want, and the compiler will do the rest. You can validly override none, one, or both.
Just the getter:
Just the setter:
The methods for object types (and covering atomicity) are only slightly more complicated; there are several question here on SO, and some info in the Apple docs that will explain.