Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit f045c04

Browse files
committed
[ios] MGLAnnotationView now conforms to NSSecureCoding
1 parent 4f4dc6a commit f045c04

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

platform/darwin/test/MGLCodingTests.m

+23-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ - (void)testShapeCollectionFeature {
380380
}
381381

382382
- (void)testAnnotationImage {
383-
#if TARGET_IPHONE
383+
#if TARGET_OS_IPHONE
384384
UIGraphicsBeginImageContext(CGSizeMake(10, 10));
385385
[[UIColor redColor] setFill];
386386
UIRectFill(CGRectMake(0, 0, 10, 10));
@@ -403,4 +403,26 @@ - (void)testAnnotationImage {
403403
XCTAssertEqualObjects(annotationImage, unarchivedAnnotationImage);
404404
}
405405

406+
#if TARGET_OS_IPHONE
407+
- (void)testAnnotationView {
408+
MGLAnnotationView *annotationView = [[MGLAnnotationView alloc] initWithReuseIdentifier:@"id"];
409+
annotationView.enabled = NO;
410+
annotationView.selected = YES;
411+
annotationView.draggable = YES;
412+
annotationView.centerOffset = CGVectorMake(10, 10);
413+
annotationView.scalesWithViewingDistance = NO;
414+
415+
NSString *filePath = [self temporaryFilePathForClass:[MGLAnnotationView class]];
416+
[NSKeyedArchiver archiveRootObject:annotationView toFile:filePath];
417+
418+
MGLAnnotationView *unarchivedAnnotationView = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
419+
420+
XCTAssertEqual(annotationView.enabled, unarchivedAnnotationView.enabled);
421+
XCTAssertEqual(annotationView.selected, unarchivedAnnotationView.selected);
422+
XCTAssertEqual(annotationView.draggable, unarchivedAnnotationView.draggable);
423+
XCTAssertEqualObjects(NSStringFromCGVector(annotationView.centerOffset), NSStringFromCGVector(unarchivedAnnotationView.centerOffset));
424+
XCTAssertEqual(annotationView.scalesWithViewingDistance, unarchivedAnnotationView.scalesWithViewingDistance);
425+
}
426+
#end
427+
406428
@end

platform/ios/src/MGLAnnotationView.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationViewDragState) {
5050
interactivity such as dragging, you can use an `MGLAnnotationImage` instead to
5151
conserve memory and optimize drawing performance.
5252
*/
53-
@interface MGLAnnotationView : UIView
53+
@interface MGLAnnotationView : UIView <NSSecureCoding>
5454

5555
#pragma mark Initializing and Preparing the View
5656

platform/ios/src/MGLAnnotationView.mm

+28
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ - (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
3333
return self;
3434
}
3535

36+
+ (BOOL)supportsSecureCoding {
37+
return YES;
38+
}
39+
40+
- (instancetype)initWithCoder:(NSCoder *)decoder {
41+
if (self = [super initWithCoder:decoder]) {
42+
_reuseIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:@"reuseIdentifier"];
43+
_annotation = [decoder decodeObjectOfClass:[NSObject class] forKey:@"annotation"];
44+
_centerOffset = [decoder decodeCGVectorForKey:@"centerOffset"];
45+
_scalesWithViewingDistance = [decoder decodeBoolForKey:@"scalesWithViewingDistance"];
46+
_selected = [decoder decodeBoolForKey:@"selected"];
47+
_enabled = [decoder decodeBoolForKey:@"enabled"];
48+
self.draggable = [decoder decodeBoolForKey:@"draggable"];
49+
}
50+
return self;
51+
}
52+
53+
- (void)encodeWithCoder:(NSCoder *)coder {
54+
[super encodeWithCoder:coder];
55+
[coder encodeObject:_reuseIdentifier forKey:@"reuseIdentifier"];
56+
[coder encodeObject:_annotation forKey:@"annotation"];
57+
[coder encodeCGVector:_centerOffset forKey:@"centerOffset"];
58+
[coder encodeBool:_scalesWithViewingDistance forKey:@"scalesWithViewingDistance"];
59+
[coder encodeBool:_selected forKey:@"selected"];
60+
[coder encodeBool:_enabled forKey:@"enabled"];
61+
[coder encodeBool:_draggable forKey:@"draggable"];
62+
}
63+
3664
- (void)prepareForReuse
3765
{
3866
// Intentionally left blank. The default implementation of this method does nothing.

0 commit comments

Comments
 (0)