Why AFURLRequestSerialization use KVO to observe value changing?

123 Views Asked by At

After reading the source code of AFURLRequestSerialization, I found that the author uses AFHTTPRequestSerializerObservedKeyPaths and NSStringFromSelector to get multiple keys such as allowsCellularAccess and cachePolicy, and uses itself as the observer to observe the value changing of these keys:

[self addObserver:self
       forKeyPath:keyPath
          options:NSKeyValueObservingOptionNew
          context:AFHTTPRequestSerializerObserverContext];

Why doesn't he just override some setters and use setters to observe the value changing?

- (void)setAllowsCellularAccess:(BOOL)allowsCellularAccess {
    //here do something else
    _allowsCellularAccess = allowsCellularAccess;
}

Is there any benefits?

0

There are 0 best solutions below