Files
MapLibreParticleLab/platform/osx/app/OfflinePackNameValueTransformer.m
Minh Nguyễn 78f93708d6 [osx] Offline pack manager in osxapp
Added an offline pack download manager to osxapp to demonstrate the use of MGLOfflineStorage with Cocoa Bindings. Like the Offline Packs view controller in iosapp, new packs are added based on the foremost map view’s current state. Double-clicking a complete offline pack opens a new map window to the pack’s bounds.
2016-03-29 11:46:27 -07:00

34 lines
1.0 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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