Skip to content

Implement CachedURLResponse. #2245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove coding.
  • Loading branch information
millenomi committed May 30, 2019
commit 6be80a7e3794feada4ed6119c2c4537dc293a3b5
46 changes: 1 addition & 45 deletions Foundation/URLCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,51 +47,7 @@ extension URLCache {
It is used to maintain characteristics and attributes of a cached
object.
*/
open class CachedURLResponse : NSObject, NSSecureCoding, NSCopying {

public required init?(coder aDecoder: NSCoder) {
guard aDecoder.allowsKeyedCoding else {
/* Unkeyed unarchiving is not supported. */
return nil
}

guard let data = aDecoder.decodeObject(of: NSData.self, forKey: "Data") else {
return nil
}
guard let response = aDecoder.decodeObject(of: URLResponse.self, forKey: "URLResponse") else {
return nil
}
guard let storagePolicyValue = aDecoder.decodeObject(of: NSNumber.self, forKey: "StoragePolicy") else {
return nil
}
guard let storagePolicy = URLCache.StoragePolicy(rawValue: storagePolicyValue.uintValue) else {
return nil
}
let userInfo = aDecoder.decodeObject(of: NSDictionary.self, forKey: "UserInfo")

self.data = data as Data
self.response = response
self.storagePolicy = storagePolicy
self.userInfo = userInfo?._swiftObject
}

open func encode(with aCoder: NSCoder) {
guard aCoder.allowsKeyedCoding else {
fatalError("We do not support saving to a non-keyed coder.")
}

aCoder.encode(data as NSData, forKey: "Data")
aCoder.encode(response, forKey: "URLResponse")
aCoder.encode(NSNumber(value: storagePolicy.rawValue), forKey: "StoragePolicy")
if let userInfo = userInfo {
aCoder.encode(userInfo._nsObject, forKey: "UserInfo")
}
}

static public var supportsSecureCoding: Bool {
return true
}

open class CachedURLResponse : NSObject, NSCopying {
open override func copy() -> Any {
return copy(with: nil)
}
Expand Down