iOS 远程资源加载:SVNetworking
SVNetworking 是一个 iOS 上用于加载远程资源的开发包,使用 key-value 观察方式进行设计。
SVNetworking
SVNetworking is a library for networking and resource loading in iOS applications. It is primarily designed for use with key-value observing, and attempts to make use of functional concepts when possible. To aid in this, implementations of property binding and some higher-order functions are included.
Requests
Requests are handled by a subclasses ofSVRequest. These are fairly simple classes - SVNetworking is generally lightweight, and tries to solve most problems while maintaining elegance, instead of solving all possible problems.
SVRequestuses delegation instead of completion/failure blocks - while this often results in slightly more code, it avoids retain cycles, "weakSelf", and nested "callback hell".
While the request classes were originally the entirety of SVNetworking, the focus of the library is now on resource loading.
Remote Resources
The abstract classSVRemoteResourceprovides a base for implementations of resources that are loaded asynchronously.SVRemoteResourcehas no coupling withSVRequestor network requests in general (although some subclasses do) - it can be easily used with any other networking library, or with any other asynchronous process with an end result. For example:
- Loading large files from disk
- Procedural generation
- Video processing
Resources are generally uniqued for memory benefits (among others), but this is optional.
Remote resources are intended for use with key-value observing. The binding categories onNSObjectand theSV_KEYPATHmacro are intended to aid in this.