How to override getter for KVO compatible property?

I want to subclass NSOperation that I need to set up -isReady

getter for a KVO compatible property. My override would do the boolean - both my custom test and super

method version. But the override must still support KVO compliance. So how?

+3


source to share


1 answer


Nothing fancy as the synthesized properties meet the KVC and KVO requirements:

Property:

@property (nonatomic, readwrite, getter=isReady) BOOL ready;`

      

Implementation:



@synthesize ready;

- (BOOL) isReady {
   // your custom logic here.
}

      

For a subclass, the NSOperation

KVO notifications for these properties will be automatic. You don't need to do anything (you don't need to call will / didSetValueForKey). If the behavior of attributes NSOperation

like isReady

or isFinished

depends on other properties or key paths, be sure to register them with KVO:

+ (NSSet *) keyPathsForValuesAffectingIsFinished {
    NSSet   *result = [NSSet setWithObject:@"finished"];
    return result;
}

      

+1


source







All Articles