forked from jsonmodel/jsonmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONCacheFile.m
More file actions
47 lines (41 loc) · 1.12 KB
/
JSONCacheFile.m
File metadata and controls
47 lines (41 loc) · 1.12 KB
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
//
// JSONCacheFile.m
// JSONModelDemo_iOS
//
// Created by Marin Todorov on 3/25/13.
// Copyright (c) 2013 Underplot ltd. All rights reserved.
//
#import "JSONCacheFile.h"
@implementation JSONCacheFile
-(instancetype)initWithKey:(NSString*)key andEtag:(NSString*)etag
{
self = [super init];
if (self!=nil) {
if (etag!=nil) {
self.fileName = [NSString stringWithFormat:@"%@~%@~etag",key,etag];
} else {
self.fileName = key;
}
self.modificationTime = [[NSDate date] timeIntervalSinceReferenceDate];
}
return self;
}
-(void)setFileName:(NSString *)fileName
{
_fileName = fileName;
if ([_fileName hasSuffix:@"etag"]) {
//etag attached to object name
NSArray* nameParts = [_fileName componentsSeparatedByString:@"~"];
if (nameParts.count>2) {
_etag = nameParts[nameParts.count-2];
_key = nameParts[nameParts.count-3];
}
} else {
_key = fileName;
}
}
-(NSString*)description
{
return [@{@"key":self.key,@"name":self.fileName,@"etag":self.etag?self.etag:@""} debugDescription];
}
@end