Winter is a lightweight generic cache framework written in Swift 5.7. For the Swift 3 version, please refer to the master branch.
- iOS 11.0+, tvOS 11.0+, macOS 10.13+, watchOS 6.0+
- Swift 5.7
Winter
could be installed via Swift Package Manager. Open Xcode and go to File -> Add Packages..., search https://github.com/hengyu/Winter.git
, and add the package as one of your project's dependency.
Encode and decode methods should be implemented if a type conforms to DataRepresentable
protocol.
extension GHMember: DataRepresentable {
public class func decode(with data: Data) -> GHMember? {
// decode to the desired object using the given data
if let raw = String.decode(with: data), mem = GHMember(rawString: raw) {
return mem
}
return nil
}
public func encode() -> Data? {
// encode the instance to data
return self.rawString?.encode()
}
}
The usage is quite simple, just import the Winter
framework and create a cache object manager:
let cache = Winter.Cache<Data>(name: "data") // initialize a cache
cache.setObject(myData, forKey: "example") // add an object
cache.object(forKey: "example") { obj, err in
// get an object
// ...
}
Winter provides a memory and disk cache for UIImage
, Data
, Date
, String
or any other type that can be read or written as data.
Winter is available under the MIT License.