support cachedResponseForRequest
Closed this issue · 4 comments
dimohamdy commented
please support mapping of Response get from NSURLCache
let cachedResponse = NSURLCache.sharedURLCache().cachedResponseForRequest(request)
dimohamdy commented
i support it
//How to use
let response: [Product] = NSURLCache.sharedURLCache().cachedResponseForRequest(request)!.ObjectMapperArraySerializer()
import Foundation
import ObjectMapper
extension NSCachedURLResponse {
public func ObjectMapperSerializer<T: Mappable>() -> T?{
do {
let JSON = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
return Mapper<T>().map(JSON)!
} catch {
return nil
}
}
public func ObjectMapperArraySerializer<T: Mappable>() -> [T]{
do {
let JSON = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
return Mapper<T>().mapArray(JSON)!
} catch {
return []
}
}
}
tristanhimmelman commented
I do not plan on adding this functionality at the time. Thanks for the suggestion
erudonja1 commented
@dimohamdy
Thank you, this solution works for me, since I had to manually cache response from alamofire(because server headers was set to no-cache etc.).
dimohamdy commented
@erudonja1 you can check this
https://github.com/dimohamdy/CachedResponseObjectMapper