@@ -47,26 +47,13 @@ extension URLCache {
47
47
It is used to maintain characteristics and attributes of a cached
48
48
object.
49
49
*/
50
- open class CachedURLResponse : NSObject , NSSecureCoding , NSCopying {
51
-
52
- public required init ? ( coder aDecoder: NSCoder ) {
53
- NSUnimplemented ( )
54
- }
55
-
56
- open func encode( with aCoder: NSCoder ) {
57
- NSUnimplemented ( )
58
- }
59
-
60
- static public var supportsSecureCoding : Bool {
61
- return true
62
- }
63
-
50
+ open class CachedURLResponse : NSObject , NSCopying {
64
51
open override func copy( ) -> Any {
65
52
return copy ( with: nil )
66
53
}
67
54
68
55
open func copy( with zone: NSZone ? = nil ) -> Any {
69
- NSUnimplemented ( )
56
+ return self
70
57
}
71
58
72
59
/*!
@@ -81,7 +68,12 @@ open class CachedURLResponse : NSObject, NSSecureCoding, NSCopying {
81
68
corresponding to the given response.
82
69
@result an initialized CachedURLResponse.
83
70
*/
84
- public init ( response: URLResponse , data: Data ) { NSUnimplemented ( ) }
71
+ public init ( response: URLResponse , data: Data ) {
72
+ self . response = response. copy ( ) as! URLResponse
73
+ self . data = data
74
+ self . userInfo = nil
75
+ self . storagePolicy = . allowed
76
+ }
85
77
86
78
/*!
87
79
@method initWithResponse:data:userInfo:storagePolicy:
@@ -95,35 +87,69 @@ open class CachedURLResponse : NSObject, NSSecureCoding, NSCopying {
95
87
@param storagePolicy an URLCache.StoragePolicy constant.
96
88
@result an initialized CachedURLResponse.
97
89
*/
98
- public init ( response: URLResponse , data: Data , userInfo: [ AnyHashable : Any ] ? = [ : ] , storagePolicy: URLCache . StoragePolicy ) { NSUnimplemented ( ) }
90
+ public init ( response: URLResponse , data: Data , userInfo: [ AnyHashable : Any ] ? = nil , storagePolicy: URLCache . StoragePolicy ) {
91
+ self . response = response. copy ( ) as! URLResponse
92
+ self . data = data
93
+ self . userInfo = userInfo
94
+ self . storagePolicy = storagePolicy
95
+ }
99
96
100
97
/*!
101
98
@method response
102
99
@abstract Returns the response wrapped by this instance.
103
100
@result The response wrapped by this instance.
104
101
*/
105
- /*@NSCopying*/ open var response : URLResponse { NSUnimplemented ( ) }
102
+ /*@NSCopying*/ open private ( set ) var response : URLResponse
106
103
107
104
/*!
108
105
@method data
109
106
@abstract Returns the data of the receiver.
110
107
@result The data of the receiver.
111
108
*/
112
- /*@NSCopying*/ open var data : Data { NSUnimplemented ( ) }
109
+ /*@NSCopying*/ open private ( set ) var data : Data
113
110
114
111
/*!
115
112
@method userInfo
116
113
@abstract Returns the userInfo dictionary of the receiver.
117
114
@result The userInfo dictionary of the receiver.
118
115
*/
119
- open var userInfo : [ AnyHashable : Any ] ? { NSUnimplemented ( ) }
116
+ open private ( set ) var userInfo : [ AnyHashable : Any ] ?
120
117
121
118
/*!
122
119
@method storagePolicy
123
120
@abstract Returns the URLCache.StoragePolicy constant of the receiver.
124
121
@result The URLCache.StoragePolicy constant of the receiver.
125
122
*/
126
- open var storagePolicy : URLCache . StoragePolicy { NSUnimplemented ( ) }
123
+ open private( set) var storagePolicy : URLCache . StoragePolicy
124
+
125
+ open override func isEqual( _ value: Any ? ) -> Bool {
126
+ switch value {
127
+ case let other as CachedURLResponse :
128
+ return self . isEqual ( to: other)
129
+ default :
130
+ return false
131
+ }
132
+ }
133
+
134
+ private func isEqual( to other: CachedURLResponse ) -> Bool {
135
+ if self === other {
136
+ return true
137
+ }
138
+
139
+ // We cannot compare userInfo because of the values are Any, which
140
+ // doesn't conform to Equatable.
141
+ return self . response == other. response &&
142
+ self . data == other. data &&
143
+ self . storagePolicy == other. storagePolicy
144
+ }
145
+
146
+ open override var hash : Int {
147
+ var hasher = Hasher ( )
148
+ hasher. combine ( response)
149
+ hasher. combine ( data)
150
+ hasher. combine ( storagePolicy)
151
+ return hasher. finalize ( )
152
+ }
127
153
}
128
154
129
155
open class URLCache : NSObject {
0 commit comments