forked from rs/SDURLCache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDCachedURLResponse.m
65 lines (52 loc) · 1.77 KB
/
SDCachedURLResponse.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// SDCachedURLResponse.m
// SDURLCache
//
// Created by Olivier Poitrey on 12/05/12.
// Copyright (c) 2012 Dailymotion. All rights reserved.
//
#import "SDCachedURLResponse.h"
@implementation SDCachedURLResponse
@synthesize response;
+ (id)cachedURLResponseWithNSCachedURLResponse:(NSCachedURLResponse *)response
{
SDCachedURLResponse *wrappedResponse = [[SDCachedURLResponse alloc] init];
wrappedResponse.response = response;
return [wrappedResponse autorelease];
}
#pragma mark NSCopying Methods
- (id)copyWithZone:(NSZone *)zone
{
SDCachedURLResponse *newResponse = [[[self class] allocWithZone:zone] init];
if (newResponse)
{
newResponse.response = [[self.response copyWithZone:zone] autorelease];
}
return newResponse;
}
#pragma mark NSCoding Methods
- (void)encodeWithCoder:(NSCoder *)coder
{
// force write the data of underlying cached response
[coder encodeDataObject:self.response.data];
[coder encodeObject:self.response.response forKey:@"response"];
[coder encodeObject:self.response.userInfo forKey:@"userInfo"];
[coder encodeInt:self.response.storagePolicy forKey:@"storagePolicy"];
}
- (id)initWithCoder:(NSCoder *)coder
{
if ((self = [super init]))
{
self.response = [[[NSCachedURLResponse alloc] initWithResponse:[coder decodeObjectForKey:@"response"]
data:[coder decodeDataObject]
userInfo:[coder decodeObjectForKey:@"userInfo"]
storagePolicy:[coder decodeIntForKey:@"storagePolicy"]] autorelease];
}
return self;
}
- (void)dealloc
{
[response release], response = nil;
[super dealloc];
}
@end