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?