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.
34 lines
1.0 KiB
Objective-C
34 lines
1.0 KiB
Objective-C
#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
|