blob: 2825e48ed3166fd132f34c97f8d5ee94e24f6240 (
plain)
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
|
#import "OfflinePackNameValueTransformer.h"
static NSString * const MBXOfflinePackContextNameKey = @"Name";
@implementation OfflinePackNameValueTransformer
+ (Class)transformedValueClass {
return [NSString class];
}
+ (BOOL)allowsReverseTransformation {
return YES;
}
- (NSString *)transformedValue:(NSData *)context {
NSAssert([context isKindOfClass:[NSData class]], @"Context should be NSData.");
NSDictionary *userInfo = [NSKeyedUnarchiver unarchiveObjectWithData:context];
NSAssert([userInfo isKindOfClass:[NSDictionary class]], @"Context of offline pack isn’t a dictionary.");
NSString *name = userInfo[MBXOfflinePackContextNameKey];
NSAssert([name isKindOfClass:[NSString class]], @"Name of offline pack isn’t a string.");
return name;
}
- (NSData *)reverseTransformedValue:(NSString *)name {
NSAssert([name isKindOfClass:[NSString class]], @"Name should be a string.");
return [NSKeyedArchiver archivedDataWithRootObject:@{
MBXOfflinePackContextNameKey: name,
}];
}
@end
|