11
11
@const NSHTTPCookieName
12
12
@discussion Key for cookie name
13
13
*/
14
- public let NSHTTPCookieName : String = " " // NSUnimplemented
14
+ public let NSHTTPCookieName : String = " Name "
15
15
16
16
/*!
17
17
@const NSHTTPCookieValue
18
18
@discussion Key for cookie value
19
19
*/
20
- public let NSHTTPCookieValue : String = " " // NSUnimplemented
20
+ public let NSHTTPCookieValue : String = " Value "
21
21
22
22
/*!
23
23
@const NSHTTPCookieOriginURL
24
24
@discussion Key for cookie origin URL
25
25
*/
26
- public let NSHTTPCookieOriginURL : String = " " // NSUnimplemented
26
+ public let NSHTTPCookieOriginURL : String = " OriginURL "
27
27
28
28
/*!
29
29
@const NSHTTPCookieVersion
30
30
@discussion Key for cookie version
31
31
*/
32
- public let NSHTTPCookieVersion : String = " " // NSUnimplemented
32
+ public let NSHTTPCookieVersion : String = " Version "
33
33
34
34
/*!
35
35
@const NSHTTPCookieDomain
36
36
@discussion Key for cookie domain
37
37
*/
38
- public let NSHTTPCookieDomain : String = " " // NSUnimplemented
38
+ public let NSHTTPCookieDomain : String = " Domain "
39
39
40
40
/*!
41
41
@const NSHTTPCookiePath
42
42
@discussion Key for cookie path
43
43
*/
44
- public let NSHTTPCookiePath : String = " " // NSUnimplemented
44
+ public let NSHTTPCookiePath : String = " Path "
45
45
46
46
/*!
47
47
@const NSHTTPCookieSecure
48
48
@discussion Key for cookie secure flag
49
49
*/
50
- public let NSHTTPCookieSecure : String = " " // NSUnimplemented
50
+ public let NSHTTPCookieSecure : String = " Secure "
51
51
52
52
/*!
53
53
@const NSHTTPCookieExpires
54
54
@discussion Key for cookie expiration date
55
55
*/
56
- public let NSHTTPCookieExpires : String = " " // NSUnimplemented
56
+ public let NSHTTPCookieExpires : String = " Expires "
57
57
58
58
/*!
59
59
@const NSHTTPCookieComment
60
60
@discussion Key for cookie comment text
61
61
*/
62
- public let NSHTTPCookieComment : String = " " // NSUnimplemented
62
+ public let NSHTTPCookieComment : String = " Comment "
63
63
64
64
/*!
65
65
@const NSHTTPCookieCommentURL
66
66
@discussion Key for cookie comment URL
67
67
*/
68
- public let NSHTTPCookieCommentURL : String = " " // NSUnimplemented
68
+ public let NSHTTPCookieCommentURL : String = " CommentURL "
69
69
70
70
/*!
71
71
@const NSHTTPCookieDiscard
72
72
@discussion Key for cookie discard (session-only) flag
73
73
*/
74
- public let NSHTTPCookieDiscard : String = " " // NSUnimplemented
74
+ public let NSHTTPCookieDiscard : String = " Discard "
75
75
76
76
/*!
77
77
@const NSHTTPCookieMaximumAge
78
78
@discussion Key for cookie maximum age (an alternate way of specifying the expiration)
79
79
*/
80
- public let NSHTTPCookieMaximumAge : String = " " // NSUnimplemented
80
+ public let NSHTTPCookieMaximumAge : String = " Max-Age "
81
81
82
82
/*!
83
83
@const NSHTTPCookiePort
84
84
@discussion Key for cookie ports
85
85
*/
86
- public let NSHTTPCookiePort : String = " " // NSUnimplemented
86
+ public let NSHTTPCookiePort : String = " Port "
87
87
88
88
89
89
/*!
@@ -95,6 +95,7 @@ public let NSHTTPCookiePort: String = "" // NSUnimplemented
95
95
attributes of a cookie.
96
96
*/
97
97
public class NSHTTPCookie : NSObject {
98
+ var _properties : [ String : AnyObject ]
98
99
99
100
/*!
100
101
@method initWithProperties:
@@ -219,7 +220,21 @@ public class NSHTTPCookie : NSObject {
219
220
dictionary keys is invalid, for example because a required key is
220
221
missing, or a recognized key maps to an illegal value.
221
222
*/
222
- public init ? ( properties: [ String : AnyObject ] ) { NSUnimplemented ( ) }
223
+ public init ? ( properties: [ String : AnyObject ] ) {
224
+ func isValidProperty( property: String ? ) -> Bool {
225
+ if let propertyValue = property {
226
+ return propertyValue. length > 0 && ( propertyValue as NSString ) . rangeOfString ( " /n " ) . location == NSNotFound
227
+ }
228
+ return false
229
+ }
230
+ if !isValidProperty( properties [ NSHTTPCookiePath] as? String )
231
+ || !isValidProperty( properties [ NSHTTPCookieDomain] as? String )
232
+ || !isValidProperty( properties [ NSHTTPCookieName] as? String )
233
+ || !isValidProperty( properties [ NSHTTPCookieValue] as? String ) {
234
+ return nil
235
+ }
236
+ _properties = properties
237
+ }
223
238
224
239
/*!
225
240
@method cookieWithProperties:
@@ -268,7 +283,9 @@ public class NSHTTPCookie : NSObject {
268
283
for descriptions of the supported keys and values.
269
284
@result The dictionary representation of the receiver.
270
285
*/
271
- public var properties : [ String : AnyObject ] ? { NSUnimplemented ( ) }
286
+ public var properties : [ String : AnyObject ] ? {
287
+ return _properties
288
+ }
272
289
273
290
/*!
274
291
@method version
@@ -277,21 +294,27 @@ public class NSHTTPCookie : NSObject {
277
294
Version 1 maps to RFC2965 cookies. There may be future versions.
278
295
@result the version of the receiver.
279
296
*/
280
- public var version : Int { NSUnimplemented ( ) }
297
+ public var version : Int {
298
+ return ( _properties [ NSHTTPCookieVersion] as! Int )
299
+ }
281
300
282
301
/*!
283
302
@method name
284
303
@abstract Returns the name of the receiver.
285
304
@result the name of the receiver.
286
305
*/
287
- public var name : String { NSUnimplemented ( ) }
306
+ public var name : String {
307
+ return ( _properties [ NSHTTPCookieName] as! NSString ) . _swiftObject
308
+ }
288
309
289
310
/*!
290
311
@method value
291
312
@abstract Returns the value of the receiver.
292
313
@result the value of the receiver.
293
314
*/
294
- public var value : String { NSUnimplemented ( ) }
315
+ public var value : String {
316
+ return ( _properties [ NSHTTPCookieValue] as! NSString ) . _swiftObject
317
+ }
295
318
296
319
/*!
297
320
@method expiresDate
@@ -302,7 +325,12 @@ public class NSHTTPCookie : NSObject {
302
325
date. This will be the case only for "session-only" cookies.
303
326
@result The expires date of the receiver.
304
327
*/
305
- /*@NSCopying*/ public var expiresDate : NSDate ? { NSUnimplemented ( ) }
328
+ /*@NSCopying*/ public var expiresDate : NSDate ? {
329
+ if let expiresDate = _properties [ NSHTTPCookieExpires] as? NSDate {
330
+ return expiresDate
331
+ }
332
+ return nil
333
+ }
306
334
307
335
/*!
308
336
@method isSessionOnly
@@ -311,7 +339,9 @@ public class NSHTTPCookie : NSObject {
311
339
session (regardless of expiration date), NO if receiver need not
312
340
be discarded at the end of the session.
313
341
*/
314
- public var sessionOnly : Bool { NSUnimplemented ( ) }
342
+ public var sessionOnly : Bool {
343
+ return !( _properties [ NSHTTPCookieExpires] is NSDate )
344
+ }
315
345
316
346
/*!
317
347
@method domain
@@ -322,7 +352,9 @@ public class NSHTTPCookie : NSObject {
322
352
restrictions are valid. See RFC 2965 for more detail.
323
353
@result The domain of the receiver.
324
354
*/
325
- public var domain : String { NSUnimplemented ( ) }
355
+ public var domain : String {
356
+ return ( _properties [ NSHTTPCookieDomain] as! NSString ) . _swiftObject
357
+ }
326
358
327
359
/*!
328
360
@method path
@@ -332,7 +364,9 @@ public class NSHTTPCookie : NSObject {
332
364
be sent for children of that path, so "/" is the most general.
333
365
@result The path of the receiver.
334
366
*/
335
- public var path : String { NSUnimplemented ( ) }
367
+ public var path : String {
368
+ return ( _properties [ NSHTTPCookiePath] as! NSString ) . _swiftObject
369
+ }
336
370
337
371
/*!
338
372
@method isSecure
@@ -370,7 +404,9 @@ public class NSHTTPCookie : NSObject {
370
404
@result The comment of the receiver, or nil if the receiver has no
371
405
comment.
372
406
*/
373
- public var comment : String ? { NSUnimplemented ( ) }
407
+ public var comment : String ? {
408
+ return ( _properties [ NSHTTPCookieComment] as! NSString ) . _swiftObject
409
+ }
374
410
375
411
/*!
376
412
@method commentURL
@@ -381,7 +417,12 @@ public class NSHTTPCookie : NSObject {
381
417
@result The comment URL of the receiver, or nil if the receiver
382
418
has no comment URL.
383
419
*/
384
- /*@NSCopying*/ public var commentURL : NSURL ? { NSUnimplemented ( ) }
420
+ /*@NSCopying*/ public var commentURL : NSURL ? {
421
+ if let commentURL = _properties [ NSHTTPCookieCommentURL] as? NSURL {
422
+ return commentURL
423
+ }
424
+ return nil
425
+ }
385
426
386
427
/*!
387
428
@method portList
0 commit comments