yud*_*989 8 afnetworking alamofire afnetworking-3
在阅读了源代码之后AFURLRequestSerialization,我发现作者使用AFHTTPRequestSerializerObservedKeyPaths和NSStringFromSelector获取多个键,例如allowsCellularAccess和cachePolicy,并使用自己作为观察者来观察这些键的值变化:
[self addObserver:self
forKeyPath:keyPath
options:NSKeyValueObservingOptionNew
context:AFHTTPRequestSerializerObserverContext];
Run Code Online (Sandbox Code Playgroud)
他为什么不覆盖一些setter并使用setter来观察值的变化?
- (void)setAllowsCellularAccess:(BOOL)allowsCellularAccess {
//here do something else
_allowsCellularAccess = allowsCellularAccess;
}
Run Code Online (Sandbox Code Playgroud)
有什么好处吗?
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |